POJ - 2007 Scrambled Polygon (凸包)
阿新 • • 發佈:2018-11-14
連結:
http://poj.org/problem?id=2007
題意:
逆時針輸出凸多邊形的點.
思路:
排序,按叉乘排
程式碼:
#include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm> #include <iostream> using namespace std; struct point { int x,y; }p[55]; int cmp(point a,point b,point c) { return (c.x-a.x)*(b.y-a.y) - (c.y - a.y) * (b.x - a.x); } bool cmp1(point a,point b) { return cmp(p[0],a,b) < 0; } int main() { int n = 0; while(cin>>p[n].x>>p[n].y) n++; sort(p+1,p+n,cmp1); for(int i = 0; i < n;i++) { printf("(%d,%d)\n",p[i].x,p[i].y); } return 0; }