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 |
大哥大姐的帮我看看为什么错,测试数据都对了我是先算出每一个点所对应在x轴上可能的雷达的范围后,进行排序,在进行贪心…… #include<stdio.h> float a[1010][2],first,sec,temp; main() { int n,d,i,j,sum,k=1,flag,x,y; while(scanf("%d%d",&n,&d)!=EOF) { flag=1; if(n==0&&d==0) break; for(i=1;i<=n;i++) { scanf("%d%d",&x,&y); a[i][0]=x-sqrt(d*d-y*y); a[i][1]=x+sqrt(d*d-y*y); if(y>d||y<0||d<=0) flag=0; } for(i=1;i<n&&flag;i++) for(j=i+1;j<=n;j++) { if(a[i][0]>a[i][1]) { temp=a[i][0];a[i][0]=a[j][0];a[j][0]=temp; temp=a[i][1];a[i][1]=a[j][1];a[j][1]=temp; } else if(a[i][0]==a[j][0]&&a[i][1]<a[j][1]) { temp=a[i][1];a[i][1]=a[j][1];a[j][1]=temp; } } first=a[1][0];sec=a[1][1];sum=1; for(i=2;i<=n&&flag;i++) { if(a[i][0]-sec<=1e-6&&a[i][1]-sec>=1e-6) first=a[i][0]; else if(a[i][1]-sec<=1e-6) sec=a[i][1]; else if(a[i][0]-sec>=1e-6) {first=a[i][0];sec=a[i][1];sum++;} } printf("Case %d: %d\n",k++,flag?sum:-1); } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator