标签:
题目链接:http://poj.org/problem?id=1328
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 67443 | Accepted: 15121 |
Description
Input
Output
Sample Input
3 2 1 2 -3 1 2 1 1 2 0 2 0 0
Sample Output
Case 1: 2 Case 2: 1
Source
#include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> using namespace std; struct node { double x,y; } a[1005]; struct len { double l, r; } ans[1005]; bool cmp(len x1, len x2) { if(fabs(x1.l-x2.l)<1e-10) return x1.r < x2.r; return x1.l < x2.l; } int main() { int n; double d; int k=1; while(scanf("%d%lf",&n, &d),n+d) { int flag = 0; for(int i=0; i<n; i++) { scanf("%lf%lf",&a[i].x,&a[i].y); if(a[i].y-d > 1e-10) { flag = 1; } } int s = 1; if(flag) s=-1; else { for(int i=0; i<n; i++) { double l = sqrt(pow(d,2) - pow(a[i].y,2)); ans[i].l = a[i].x - l; ans[i].r = a[i].x + l; } sort(ans, ans+n, cmp); double R = ans[0].r; for(int i=1; i<n; i++) { if(ans[i].l-R > 1e-10) { s++; R = ans[i].r; } else { R = min(R, ans[i].r); } } } printf("Case %d: %d\n",k++,s); } return 0; }
标签:
原文地址:http://www.cnblogs.com/mengzhong/p/5038761.html