Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
直接极坐标排序,每次取最小值,再根据最小值对后面的点排序。 不能说数据弱..应该说数据给的好。。。RT #include <iostream> #include <fstream> #include <cmath> #include <cstring> #include <cstdio> #include <algorithm> using namespace std; #define L(x) rt<<1 #define R(x) rt<<1|1 #define lson l, m, rt<<1 #define rson m+1, r, rt<<1|1 #define LL(x) ((x)<<1) #define RR(x) ((x)<<1|1) #define MID ((l+r)>>1) #define BUG1 puts("BUG11\n") #define BUG2 puts("BUG22\n") #define LL long long #define MAX(a,b) (a>b?a:b) #define MIN(a,b) (a>b?b:a) #define FOR(i,a,b) for(int (i)=(a);(i)<=(b);(i)++) #define FF(i,a) for(int i=0;i<a;i++) #define FD(i,a,b) for(int i=a;i>=b;i--) #define STOP int stop;scanf("%d", &stop) #define PD(x) printf("%d",(x)) #define PP printf(" ") #define SD(x) scanf("%d", &(x)) #define SF(x) scanf("%lf", &(x)) #define LN printf("\n"); #define swap(a,b) a=a xor b;b= a xor b;a=a xor b; #define EPS 1e-6 const int maxn= 10000; int idx; struct Point { int id; double x,y; Point(){} Point(double _x, double _y): x(_x),y(_y){} void read(){SF(x);SF(y);} void writeln(){printf("id=%d %lf------%lf\n",id,x,y);} double dis(Point b){ return sqrt((x-b.x)*(x-b.x)+(y-b.y)*(y-b.y)); } }p[maxn]; int dblcmp(double x) {return fabs(x)<EPS?0:x>0?1:-1; } double Cross(Point a, Point b, Point c){ return (b.x-a.x)*(c.y-a.y)-(c.x-a.x)*(b.y-a.y); } bool cmp1(Point a, Point b){ if (dblcmp(a.y-b.y)==0) return (dblcmp(a.x-b.x)<0); return dblcmp(a.y-b.y)<0; } bool cmp2(Point a, Point b){ int cmp2c= dblcmp(Cross(p[idx],a,b)); return cmp2c>0; } void Graham(int n){ idx= 0; sort(p,n+p,cmp1); sort(p+1+idx,n+p,cmp2); idx++; while(idx<n){ sort(p+1+idx,n+p,cmp2); idx++; } printf("%d",idx); FF(i,idx){ printf(" %d",p[i].id); } LN; } int main(){ int ncase; SD(ncase); while(ncase--){ int n; SD(n); FF(i,n){ SD(p[i].id); p[i].read(); } Graham(n); } // STOP; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator