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" #include "math.h" #include "algorithm" using namespace std; const double eps=0.000001; const int MAX=50050; int index=1; struct Point { double x,y; }; Point ans[MAX]; double det(Point p1,Point p2,Point p3) { return (p1.x*p2.y+p3.x*p1.y+p2.x*p3.y-p3.x*p2.y-p2.x*p1.y-p1.x*p3.y); } void merge1(Point a[],int min ,int max) { double smax=0,s; int i,k=0; for(i=min+1;i<max;i++) { s=det(a[min],a[max],a[i]); if(smax>s) { smax=s; k=i; } } if(k!=0) { ans[index].x=a[k].x; ans[index++].y=a[k].y; merge1(a,min,k); merge1(a,k,max); } } void merge2(Point a[],int min ,int max) { double smin=0,s; int i,k=0; for(i=min+1;i<max;i++) { s=det(a[min],a[max],a[i]); if(smin<s) { smin=s; k=i; } } if(k!=0) { ans[index].x=a[k].x; ans[index++].y=a[k].y; merge2(a,min,k); merge2(a,k,max); } } int cmp_x(const void*p ,const void*q) { double temp=((Point*)p)->x-((Point*)q)->x; if(temp>0) return 1; else if(fabs(temp)<eps) return 0; else return -1; } int _tmain(int argc, _TCHAR* argv[]) { int i,j,n,temp=0; Point a[MAX]; cin>>n; for(i=0;i<n;i++) cin>>a[i].x>>a[i].y; qsort(a,n,sizeof(a[0]),cmp_x); ans[0].x=a[0].x; ans[0].y=a[0].y; merge1(a,0,n-1); merge2(a,0,n-1); ans[++index].x=a[n-1].x; ans[++index].y=a[n-1].y; for(i=0;i<index;i++) for(j=i;j<=index;j++) if(temp<(ans[i].x-ans[j].x)*(ans[i].x-ans[j].x)+(ans[i].y-ans[j].y)*(ans[i].y-ans[j].y)) temp=(ans[i].x-ans[j].x)*(ans[i].x-ans[j].x)+(ans[i].y-ans[j].y)*(ans[i].y-ans[j].y); cout<<temp; return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator