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 <cmath> double min2[1005],max2[1005]; double ma,mi; int nc; using namespace std; void randg(double dd,double yy,double x1) { ma=sqrt(dd*dd-yy*yy)+x1; mi=x1-sqrt(dd*dd-yy*yy); //cout<<'('<<mi<<','<<ma<<')'<<endl; } int qujiao(int first,int second)//取交集 { if (min2[first]<=max2[second]&&min2[first]>min2[second]&&max2[first]>max2[second]) { min2[second]=min2[first]; } else { if (min2[first]<min2[second]&&max2[first]>=min2[second]&&max2[first]<max2[second]) { max2[second]=max2[first]; } else { if (min2[first]>min2[second]&&max2[first]<max2[second]) { min2[second]=min2[first];max2[second]=max2[first]; } else { if (min2[first]<=min2[second]&&max2[first]>=max2[second]) { ; } else { return 0;//无交集 } } } } return 1; } int findd() { int i,j,k=0; for(i=nc-1;i>0;i--) for(j=i-1;j>=0;j--) { if(max2[i]<min2[i]) break; if(max2[j]>=min2[j]&&qujiao(j,i)) { min2[j]=0; max2[j]=-1; } } for (i=0;i<nc;i++) { if(min2[i]<=max2[i]) k++; } return k; } int main() { int n,ii=0,jj=0,k=1; double d,x,y; while(cin>>nc>>d&&(nc||d)) { int flg=1,ii=0,jj=0; n=nc; while(n--) { cin>>x>>y; if ((d<y||d<0)&&flg)//y大于d时不再计算 { flg=0; } if(flg)//y小于d时计算 { randg(d,y,x); min2[ii++]=mi; max2[jj++]=ma; } } if(flg==0) cout<<"Case "<<k++<<": "<<"-1"<<endl; else { if(nc==1) cout<<"Case "<<k++<<": "<<'1'<<endl; else cout<<"Case "<<k++<<": "<<findd()<<endl; /*for (int i=0;i<nc;i++) { cout<<'('<<min2[i]<<','<<max2[i]<<')'<<endl; }*/ } } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator