登 录
PKU 1328 Radar Installation
http://acm.pku.edu.cn/JudgeOnline/problem?id=1328
我晕,太注意精度问题了让我WA了N次!!
注意我代码里给出的边界测试数据就OK了
贪心+排序:
#include <iostream> #include <cmath> #include <algorithm> using namespace std; const double EPS = 1e-7; struct Point { double x; double y; double l; double r; bool operator < (const Point &t)const { return r < t.r; } }; Point p[10002]; bool used[10002]; int main() { int i,j,k,m; int n; double d,t; int counter = 0; while (scanf("%d %lf",&n,&d)!=EOF) { if (n == 0 && d == 0) { break; } memset(used,0,sizeof(used)); counter++; bool flag = 0; for (i=0;i<n;i++) { scanf("%lf %lf",&p[i].x,&p[i].y); t = sqrt(fabs(d*d - p[i].y*p[i].y)); p[i].r = p[i].x + t; p[i].l = p[i].x - t; if ((fabs(p[i].y)>fabs(d)) || (d<0)) { flag = 1; } } if (flag) { printf("Case %d: -1/n",counter); continue; } sort(p,p+n); int cnt = 0; for (i=0;i<n;i++) { if (!used[i]) { cnt++; for (j=0;j<n;j++) { if (i!=j && !used[j]) { if (p[j].l <= p[i].r && p[j].r >= p[i].r) // if ((p[i].r-p[j].l>=EPS) && (p[j].r-p[i].r >= EPS)) { used[j] = 1; } } } used[i] = 1; } } printf("Case %d: %d/n",counter,cnt); } return 0; } /* 3 2 0 0 2 2 4 0
*/
抱歉!评论已关闭.