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 |
huys why WA, plz somebody send me his solution;)#include<iostream> #include<cmath> using namespace std; struct island { int x,y; }; int compare(const void *p1,const void *p2) { island n1=*(island *)p1,n2=*(island *)p2; if(n1.x>n2.x)return 1; if(n1.x==n2.x) { if(n1.y<n2.y)return 1; if(n1.y>n2.y)return -1; return 0; } if(n1.x<n2.x)return -1; return 0; } int main() { int n,d,t=0; while(cin>>n>>d&&n+d!=0) { island a[1000]; for(int i=0;i<n;i++) { cin>>a[i].x>>a[i].y; } qsort(a,n,sizeof(island),compare); int c=0,m=0;i=0; while(m<n) { c++; int x=a[i].x,y=a[i].y; if(y>d)break; m++; double px=double(x)+double(sqrt(d*d-y*y)); for(int j=i+1;j<n;j++) { if(double(sqrt((px-a[j].x)*(px-a[j].x)+a[j].y*a[j].y))>double(d)){i=j;break;} m++; } } if(m<n)cout<<"Case "<<++t<<": "<<-1<<endl; else cout<<"Case "<<++t<<": "<<c<<endl; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator