标签:
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 64121 | Accepted: 14418 |
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
1 #include <cmath> 2 #include <cstdio> 3 #include <algorithm> 4 using namespace std; 5 6 struct island 7 { 8 double l, r; 9 } num[1010]; 10 11 bool cmp(island l, island r) 12 { 13 if(l.l == r.l) 14 return l.r < r.r; 15 return l.l < r.l; 16 } 17 18 int main() 19 { 20 double r, x, y; int i, m, t=1; 21 while(~scanf("%d %lf", &m, &r)) 22 { 23 int flag = 0; 24 if(m == 0 && r == 0) 25 break; 26 for(i=0; i<m; i++) 27 { 28 scanf("%lf %lf", &x, &y); 29 if(y > r) 30 {flag = 1; continue; } 31 num[i].l = x - sqrt(r*r - y*y); //转化为区间问题; 32 num[i].r = x + sqrt(r*r - y*y); 33 } 34 if(flag) 35 { 36 printf("Case %d: -1\n",t++); 37 continue; 38 } 39 sort(num, num+m, cmp); 40 double temp = num[0].r; int total = 1; 41 for(i=1; i<m; i++) 42 { 43 if(num[i].l > temp){ 44 total++; 45 temp = num[i].r; 46 } 47 48 if(num[i].l <= temp) 49 { 50 if(num[i].r < temp) 51 temp = num[i].r; 52 } 53 } 54 printf("Case %d: %d\n", t++, total); 55 } 56 return 0; 57 }
Poj1328--Radar Installation(区间选点)
标签:
原文地址:http://www.cnblogs.com/fengshun/p/4693154.html