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 |
吐血啊 WA十几次 谁能帮忙瞧一下哇#include<iostream> using namespace std; #define N 50010 #define MAX 100000 struct Point { int x; int y; }P[N]; int stack[N]; int top; inline int dirc(Point p1,Point p2,Point p3) { return (p3.x-p1.x)*(p2.y-p1.y)-(p3.y-p1.y)*(p2.x-p1.x); } inline int range(Point p1,Point p2) { return (p2.x-p1.x)*(p2.x-p1.x)+(p2.y-p1.y)*(p2.y-p1.y); } int comp(const void* p1,const void* p2) { int d=dirc(P[0],*(Point*)p1,*(Point*)p2); if(d==0) return range(P[0],*(Point*)p1)-range(P[0],*(Point*)p2); return d; } int main() { int n; while(scanf("%d",&n)!=EOF) { top=-1; int i,j,pos=0,max=0,min=MAX; for(i=0;i<n;i++) { scanf("%d%d",&P[i].x,&P[i].y); if(P[i].y<min) { pos=i; min=P[i].y; } } swap(P[0],P[pos]); qsort(&P[1],n-1,sizeof(Point),comp); stack[++top]=0; stack[++top]=1; for(i=2;i<n;i++) { int d=dirc(P[stack[top-1]],P[stack[top]],P[i]); if(d<0) stack[++top]=i; else stack[top]=i; } for(i=0;i<top;i++) for(j=i+1;j<=top;j++) if(range(P[stack[i]],P[stack[j]])>max) { max=range(P[stack[i]],P[stack[j]]); } printf("%d\n",max); } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator