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 |
快排怎么会出问题呢????#include"iostream" #include"cmath" using namespace std; struct Point { double left; double right; }island; /*int cmp( const void *a , const void *b ) { Point *c = (Point *)a; Point *d = (Point *)b; if(c->left != d->left) return c->left- d->left; else return d->right - c->right; }*/ int cmp(const void *p1, const void *p2) { Point I1 = *(Point *)p1; Point I2 = *(Point *)p2; double temp = I1.left - I2.left; if (temp > 0.0) return 1; else if (temp < 0.0) return -1; else { temp = I2.right - I1.right; if (temp > 0.0) return 1; else return -1; } } int main() { Point island[1005]; int n,d,x[1005],y[1005],i,dd,count,flag; int num=0; double sqrtdy,right; while(cin>>n>>d) { num++; int flag=0; if(n==0&&d==0) break; for( i=0;i<n;i++) { cin>>x[i]>>y[i]; if(y[i]>d) flag=1; } if(flag==1) { cout<<"Case "<<num<<": "<<-1<<endl; continue; } dd=d*d; for (i = 0; i < n; i++) { sqrtdy = sqrt((double)(dd - y[i]*y[i])); island[i].left=x[i]-sqrtdy; island[i].right=x[i]+sqrtdy; } qsort(island,n,sizeof(Point),cmp); right=island[0].right; count=1; for( int j=1;j<n;j++) { if(island[j].left>right) { count++; right=island[j].right; } else { if(island[j].right<right) { right=island[j].right; } } } cout<<"Case "<<num<<": "<<count<<endl; } return 1; } /* int main() { Point points[1005]; int n,d,x[1005],y[1005],i,dd,cnt,flag; int t=0; double sqrtdy,right; while(scanf("%d%d",&n,&d)&&!(n==0&&d==0)) { t++; flag=0; int i; for(i=0;i<n;i++) { scanf("%d%d",&x[i],&y[i]); if(y[i]>d) flag=1; } if(flag) { printf("Case %d: %d\n",t, -1); continue; } dd=d*d; for (i = 0; i < n; i++) { sqrtdy = sqrt((double)(dd - y[i]*y[i])); points[i].left = x[i]-sqrtdy; points[i].right =x[i]+ sqrtdy; } qsort(points,n,sizeof(Point),cmp); cnt=1; right=points[0].right; for(i=1;i<n;i++) { if(points[i].left>right) { cnt++; right=points[i].right; } else { if (points[i].right < right) right = points[i].right; } } printf("Case %d: %d\n",t,cnt); } }*/ Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator