标签:mes algo opened less -- show this bool 凸包
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 4560 Accepted Submission(s):
1009
#include <math.h> #include <stdio.h> #include <string.h> #include <iostream> #include <algorithm> #define ll long long using namespace std; const int N = 1005; int t, n, m, ans; int top, s[N]; struct Point{ double x, y, v; int id; bool operator<(const Point &a)const{ if(y == a.y) return x < a.x; return y < a.y; } bool isEqual(Point a){ return (x == a.x && y == a.y && v == a.v); } double getCross(Point a, Point b){ return (a.x-x)*(b.y-y)-(a.y-y)*(b.x-x); } }p[N], tmp[N], stk[N]; void Graham(int cnt){ top = 1; sort(tmp, tmp+cnt); if(!cnt){ top = 0; return; } stk[0] = tmp[0]; if(cnt == 1){ top = 1; return; } stk[1] = tmp[1]; if(cnt == 2){ top = 2; return; } for(int i = 2; i < cnt; i ++){ while(top && stk[top-1].getCross(stk[top], tmp[i]) < 0) top--; stk[++top] = tmp[i]; } int len = top; stk[++top] = tmp[cnt-2]; for(int i = cnt-3; i+1; i --){ while(top != len && stk[top-1].getCross(stk[top], tmp[i]) < 0) top--; stk[++top] = tmp[i]; } } int main(){ ans = 1; while(scanf("%d", &n) && n){ double Max = 0; for(int i = 0; i < n; i ++){ scanf("%lf%lf%lf", &p[i].x, &p[i].y, &p[i].v); p[i].id = i; Max = max(Max, p[i].v); } printf("Case #%d: ", ans++); if(Max == 0){ for(int i = 0; i < n; i ++){ printf("0"); } printf("\n"); continue; } for(int i = 0; i < n-1; i ++){ for(int j = i+1; j < n; j ++){ if(p[i].isEqual(p[j])){ p[j].v = 0; s[i] = s[j] = -1; } } } int cnt = 0; for(int i = 0; i < n; i ++){ if(p[i].v == Max){ tmp[cnt++] = p[i]; } } Graham(cnt); for(int i = 0; i < top; i ++){ if(s[stk[i].id] != -1){ s[stk[i].id] = 1; } } for(int i = 0; i < n; i ++){ printf("%d", s[i] > 0); s[i] = 0; } printf("\n"); } return 0; }
标签:mes algo opened less -- show this bool 凸包
原文地址:https://www.cnblogs.com/microcodes/p/12815040.html