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!WAWAWA*10!!!! #include <iostream> #include <math.h> using namespace std; const int NN=2000; const int MAXINT=1E8; int n,d,a[NN][2]; void test() { cout<<endl; for (int i=0;i<n;++i) cout<<a[i][0]<<" "<<a[i][1]<<endl; cout<<endl; } int init() { int N; cin>>N>>d; if (N==0 && d==0) return 0; int i=0; bool cant=false; if (d<=0) { cant=true; } for (int u=0;u<N;++u) { int x,y; cin>>x>>y; //if (y<0) continue; if (cant) continue; if (y>d) { cant=true; continue; } a[i][0]=x-sqrt(d*d-y*y); a[i][1]=x+sqrt(d*d-y*y); ++i; } n=i; if (cant) return -1; return 1; } void qsort(int l,int r) { int i,j; i=l,j=r; int v=a[(i+j)>>1][0]; do { while (a[i][0]<v) ++i; while (v<a[j][0]) --j; if (i<=j) { int tmp=a[i][0]; a[i][0]=a[j][0]; a[j][0]=tmp; tmp=a[i][1]; a[i][1]=a[j][1]; a[j][1]=tmp; ++i; --j; } }while (i<j); if (i<r) qsort(i,r); if (l<j) qsort(l,j); } int cal() { qsort(0,n-1); int num=0; int l=-MAXINT,r=-MAXINT; for (int i=0;i<n;++i) { if (r<a[i][0]) { ++num; l=a[i][0]; r=a[i][1]; } else if (a[i][1]<r) r=a[i][1]; } //test(); return num; } void work() { int u=0; while (1) { ++u; int r=init(); if (r==0) return; if (r==-1) cout<<"Case "<<u<<": -1"<<endl; else cout<<"Case "<<u<<": "<<cal()<<endl; } } int main() { //freopen("in.txt","r",stdin); //freopen("out.txt","w",stdout); work(); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator