poj 1328 一直WA,求解释。
代码贴上去,好多数据都可以过,求指导!程序代码:
#include<iostream> #include<cstdio> #include<math.h> using namespace std; int in_circle(double x1,double y1,double r,double x2,double y2) { if(sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2))<=r) return 1; else return 0; } class circle { public: double x; double y; double r; }; int main() { int n,i,number,flag; int d; double x[1010],y[1010]; int l=1; while(scanf("%d%d",&n,&d)&&n!=0&&d!=0) { for(i=0;i<n;i++) cin>>x[i]>>y[i]; for(i=0;i<n;i++) { for(int j=i+1;j<n;j++) { if(y[j]<y[i]) { double t=y[i]; double k=x[i]; y[i]=y[j]; x[i]=x[j]; y[j]=t; x[j]=k; } } } //按y从小到大排序 if(y[n-1]>d) { cout<<"Case "<<l<<": -1"<<endl; l++; } else { number=1; circle c[100]; for(int i=0;i<100;i++) { c[i].y=0; c[i].r=d; } c[0].x=x[n-1]; for(int i=n;i--;i>=0) { flag=0; for(int j=0;j<number;j++) { if(in_circle(c[j].x,c[j].y,c[j].r,x[i],y[i])) { flag=1; break; } else continue; } if(flag==0) { number++; c[number-1].x=x[i]; } } cout<<"Case "<<l<<": "<<number<<endl; l++; } } }