//坐标是整形的凸包算法 int dblcmp(double t) { if(fabs(t) < 1e-8) return 0; return (t > 0) ? 1 : -1; } //求向量叉积abXac > 0 c 在ab逆时针方向 int Cross(Point a, Point b, Point c) { return (b.x-a.x)*(c.y-a.y)-(c.x-a.x)*(b.y-a.y); } //两点之间的距离 double Dis(Point a, Point b) { return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)*1.0); } //距离的平方 int Dis2(Point a, Point b) { return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y); } bool cmp(Point a, Point b) { int t = Cross(tmp[0], a, b); if(t > 0) return true; if(t == 0 && Dis2(tmp[0], a)-Dis2(tmp[0], b) < 0) return true; return false; } void Graham(int *stk, int &top, Point *tp, int N) { int i; for(i = 1; i < N; i++) { if(tp[i].y < tp[0].y || (tp[i].y == tp[0].y && tp[i].x < tp[0].x)) swap(tp[0], tp[i]); } sort(tp+1, tp+N, cmp); top = 0; stk[top++] = 0; for(i = 1; i < N; i++) { while(top > 1 && Cross(tp[stk[top-2]], tp[stk[top-1]], tp[i]) <= 0) top--; stk[top++] = i; } //栈尾再加入一个起点 stk[top++] = 0; } 题目链接:http://acm.zstu.edu.cn:8080/JudgeOnline/showproblem?problem_id=2971 题目链接:http://acm.zstu.edu.cn:8080/JudgeOnline/showproblem?problem_id=1707