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 |
Re:大哥大姐的帮我看看为什么错,测试数据都对了In Reply To:大哥大姐的帮我看看为什么错,测试数据都对了 Posted by:zgd2009 at 2009-07-24 10:18:08 > 我是先算出每一个点所对应在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; > } > > sqrt() 中,必须保证d>y吧?大哥你这样写会不会出现对负数开方? Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator