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,不知为什么啊,下面是我的代码In Reply To:通过此题,我对poj彻底绝望了…… Posted by:sanding at 2009-04-19 23:28:16 #include <iostream> #include <cmath> using namespace std; struct range{ double ranges,ranget; }; range rang[1000]; int cmp(const void *pt1,const void *pt2) { return (*(range*)pt1).ranges - (*(range*)pt2).ranges; } int main() { int n,d,cases=0; for(cases=1;cin>>n>>d&&n;cases++) { int i; bool flag=false; double x,y; for(i=0;i<n;i++) { cin>>x>>y; if(y>d) flag=true; else { rang[i].ranges=x-sqrt(d*d-y*y); rang[i].ranget=x+sqrt(d*d-y*y); } } if(flag) { cout<<"Case "<<cases<<": -1"<<endl; continue; } qsort(rang,n,sizeof(range),cmp); int cirnums=0; double s,t; for(i=0;i<n;i++) { if(!i) { s=rang[i].ranges; t=rang[i].ranget; cirnums++; } else if(rang[i].ranges<=t) { s=rang[i].ranges; t=t<rang[i].ranget?t:rang[i].ranget; } else { s=rang[i].ranges; t=rang[i].ranget; cirnums++; } } cout<<"Case "<<cases<<": "<<cirnums<<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