首页 > 代码库 > 【凸包】HDU 4946 Area of Mushroom
【凸包】HDU 4946 Area of Mushroom
注意:
1.重合的点
2.速度为0的点
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <limits.h> #include <ctype.h> #include <math.h> #include <string> #include <iostream> #include <algorithm> using namespace std; #include <queue> #include <stack> #include <vector> typedef long long LL; #define lson l, m, rt<<1 #define rson m+1, r, rt<<1|1 #define N 500005 #define maxn 505 struct Point { int x, y; int id, v; bool flag; Point(int x = 0, int y = 0) : x(x), y(y) { } } p[maxn], ch[maxn]; int ans[maxn], n; Point operator - (Point a, Point b) { return Point(a.x - b.x, a.y - b.y); } int Cross(Point a, Point b) { return a.x * b.y - a.y * b.x ; } int cmp(Point a, Point b) { if(a.x != b.x) return a.x < b.x; else if ( a.y != b.y ) return a.y < b.y; else return a.v>b.v; } int cmp1(Point a, Point b) { return a.v > b.v; } int ConvexHull(Point* p, int n, Point* ch) { sort(p, p+n, cmp); for(int i=0; i<n-1 ; i++) if(p[i].x==p[i+1].x && p[i].y==p[i+1].y && p[i].v==p[i+1].v) p[i].flag=1; int m = 0; for(int i=0; i<n; i++) { if(p[i].flag==1) continue; while(m > 1 && Cross(ch[m-1] - ch[m-2], p[i] - ch[m-2]) <0) m--; ch[m++] = p[i]; } int k = m; for(int i = n-2; i >= 0; i--) { if(p[i].flag==1) continue; while(m > k && Cross(ch[m-1] - ch[m-2], p[i]-ch[m-2]) < 0) m--; ch[m++] = p[i]; } if(n > 1) m--; return m; } int main() { int ca=1; while(~scanf("%d", &n) && n) { memset(p, 0, sizeof(p)); memset(ans, 0, sizeof(ans)); memset(ch, 0, sizeof(ch)); for(int i=1;i<=n;i++) { scanf("%d%d%d", &p[i].x, &p[i].y, &p[i].v); p[i].id=i; } printf("Case #%d: ", ca++); int i, m; sort(p+1, p+1+n, cmp1); if(p[1].v==0) { for(i=1; i<=n; i++) printf("0"); printf("\n"); continue; } for(i = 1; i < n; i++) if(p[i].v != p[i+1].v) break; m=ConvexHull(p+1, i, ch); for(i = 0; i < m; i++) ans[ch[i].id] = 1; sort (p+1, p+n+1, cmp); for(i=1; i<n; i++) if (p[i].x==p[i + 1].x && p[i].y==p[i + 1].y) if(p[i].v==p[i + 1].v) ans[p[i].id] = ans[p[i + 1].id] = 0 ; for(i=1; i<=n; i++) printf("%d", ans[i]); printf("\n"); } return 0; }
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。