Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 1113 Accepted Submission(s): 411
#include<iostream> #include<cstdio> #include<cmath> #include<cstdio> using namespace std; int n; struct node { double x; double y; }; node a[305]; double dis(node p1,node p2) { return sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y)); } int cal(int p1,int p2) { node t1,t2,t3,t4; t1=a[p1],t2=a[p2]; double s,tmp,xx,yy; tmp=dis(t1,t2); s=tmp/2.0; s=sqrt(1.0-s*s); //s为圆心到t1,t2弦长的距离 int ans1=0,ans2=0,i; xx=(t1.y-t2.y)/tmp; yy=(t2.x-t1.x)/tmp; //(xx,yy)相当于与弦长垂直的单位法向量 t3.x=(t1.x+t2.x)/2.0,t3.y=(t1.y+t2.y)/2.0; t4.x=t3.x+s*xx,t4.y=t3.y+s*yy; //t4为圆心 for(i=0;i<n;i++) { if(dis(t4,a[i])<1.0001) ans1++; } t4.x=t3.x-s*xx,t4.y=t3.y-s*yy; //t4为圆心 for(i=0;i<n;i++) { if(dis(t4,a[i])<1.0001) ans2++; } return ans1>ans2?ans1:ans2; } int main() { int i,j; int tes; scanf("%d",&tes); while(tes--) { scanf("%d",&n); for(i=0;i<n;i++) scanf("%lf%lf",&a[i].x,&a[i].y); int num; int res=1; for(i=0;i<n;i++) for(j=i+1;j<n;j++) { if(dis(a[i],a[j])<2.0001) { num=cal(i,j); if(num>res) res=num; } } printf("%d\n",res); } return 0; } //2406MS
#include<iostream> #include<cstdio> #include<cmath> #include<cstdio> using namespace std; int n; double a[305][2]; double dis(double *b1,double *b2) { return sqrt((b1[0]-b2[0])*(b1[0]-b2[0])+(b1[1]-b2[1])*(b1[1]-b2[1])); } int cal(int p1,int p2) { double t1[2],t2[2],t3[2],t4[2]; t1[0]=a[p1][0],t1[1]=a[p1][1],t2[0]=a[p2][0],t2[1]=a[p2][1]; double s,tmp,xx,yy; tmp=dis(t1,t2); s=tmp/2.0; s=sqrt(1.0-s*s); //s为圆心到t1,t2弦长的距离 int ans1=0,ans2=0,i; xx=(t1[1]-t2[1])/tmp; yy=(t2[0]-t1[0])/tmp; //(xx,yy)相当于与弦长垂直的单位法向量 t3[0]=(t1[0]+t2[0])/2.0,t3[1]=(t1[1]+t2[1])/2.0; t4[0]=t3[0]+s*xx,t4[1]=t3[1]+s*yy; //t4为圆心 for(i=0;i<n;i++) { if(dis(t4,a[i])<1.0001) ans1++; } t4[0]=t3[0]-s*xx,t4[1]=t3[1]-s*yy; //t4为圆心 for(i=0;i<n;i++) { if(dis(t4,a[i])<1.0001) ans2++; } return ans1>ans2?ans1:ans2; } int main() { int i,j; int tes; scanf("%d",&tes); while(tes--) { scanf("%d",&n); for(i=0;i<n;i++) scanf("%lf%lf",&a[i][0],&a[i][1]); int num; int res=1; for(i=0;i<n;i++) for(j=i+1;j<n;j++) { if(dis(a[i],a[j])<2.0001) { num=cal(i,j); if(num>res) res=num; } } printf("%d\n",res); } return 0; } //984MS G++