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#include <iostream> #include<math.h> using namespace std; struct qujian { int x,y; float left; float right; } qu[1010]; int compare(const void * a,const void *b) { return (*(qujian *)a).left > (*(qujian *)b).left; } int main() { int n,d,casenum=0,num=0,flag=0; //num为雷达布置个数的累积 while(1) { cin>>n>>d; if(n == 0 && d == 0) break; for(int i=0;i<n;i++) { float dx; cin>>qu[i].x>>qu[i].y; dx=sqrt(pow(d*1.0,2)-pow(qu[i].y*1.0,2)); qu[i].left=qu[i].x-dx; qu[i].right=qu[i].x+dx; } qsort(qu,n,sizeof(qu[0]),compare); if(d <= 0) flag =1; for(int i=0;i<n;i++) { if(qu[i].y > d){ flag=1; break; } } if(flag == 1) { cout<<"Case "<<++casenum<<": -1"<<endl; flag=0; continue; } int j=0; while(j<n) { int m=j+1; while(j < n && qu[m].left <= qu[j].right) m++; j=m; num++; } casenum++; cout<<"Case "<<casenum<<": "<<num<<endl; num=0; } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator