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 <stdio.h> //标准c输入输出 #include <string.h> #include <cstring> //字符串操作 #include <iostream > //标准c++输入输出 #include <math.h> #include <iomanip> // 标准C++的IO manipulator(操纵器?) using namespace std; // 使用std命名空间 typedef struct point { long x,y; }point; point b[50001]; point a[50010]; #define PI 3.14159 double mul(point a,point b,point c) { return ((a.x-c.x)*(b.y-c.y)-(a.y-c.y)*(b.x-c.x)); } double dis(point a,point b) { return sqrt((double)((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y))); } void zhang(point a[],point ch[],int n,int &len) { point tmp;int k=0,i,j,top=2; for(i=1;i<n;i++) if((a[k].y>a[i].y)||((a[k].y==a[i].y)&&(a[k].x>a[i].x))) {tmp=a[i];a[i]=a[k];a[k]=tmp;} for(i=1;i<n-1;i++) { k=i; for(j=i+1;j<n;j++) if(mul(a[j],a[k],a[0])>0||(mul(a[j],a[k],a[0])==0&&(dis(a[j],a[0])>dis(a[k],a[0])))) k=j; {tmp=a[i];a[i]=a[k];a[k]=tmp;} } ch[0]=a[0]; ch[1]=a[1];ch[2]=a[2]; for(i=3;i<n;i++) { while(mul(a[i],ch[top],ch[top-1])>=0)top--; ch[++top]=a[i]; }len=top; } int main() { int n,j,i,x; cin>>n; for(i=0;i<n;i++)cin>>a[i].x>>a[i].y; zhang(a,b,n,x); long c[50010]; for(i=0;i<=x;i++)c[i]=0; for(i=0;i<=x;i++) for(j=0;j<=x;j++)if(dis(a[i],a[j])*dis(a[i],a[j])>c[i])c[i]=dis(a[i],a[j])*dis(a[i],a[j]); long max=c[0]; for(i=1;i<=x;i++)if(c[i]>max)max=c[i]; cout<<max<<endl; return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator