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 |
ZOJAC|POJRE?高手帮忙!#include <iostream> #include <cmath> #include <algorithm> using namespace std; struct point { double l; double r; }; typedef struct point creatpoint; int cmp(const void *a , const void *b) { creatpoint *x=(point *)a; creatpoint *y=(point *)b; return x->r > y->r ? 1:-1; } inline bool change(double &a, double &b, double r) { double tmp; if (b>r) return false; tmp=sqrt(r*r-b*b); b=tmp+a; a=-tmp+a; return true; } void main() { int i,n,ks=1,radars; double d,now; creatpoint p[1005]; while (cin>>n>>d && n) { radars=0; for (i=0; i<n; i++) { cin>>p[i].l>>p[i].r;//由坐标计算过该点的圆在X轴上圆心的范围,便于贪心 if (!change(p[i].l, p[i].r, d)) { radars=-1; break; } } if (radars!=-1) { qsort(p,n,sizeof(p[0]),cmp);//排序 now=p[0].l-1; for (i=0; i<n; i++) { if (now<p[i].l) { now=p[i].r; radars++; } } } cout<<"Case "<<ks++<<": "<<radars<<endl; } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator