标签:
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 56826 | Accepted: 12814 |
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
1 #include<stdio.h> 2 #include<iostream> 3 #include<algorithm> 4 #include<math.h> 5 using namespace std; 6 struct island 7 { 8 double x , y ; 9 double left , right ; 10 }a[2000]; 11 int n ; 12 int d ; 13 bool cmp (island a , island b) 14 { 15 return a.x < b.x ; 16 } 17 18 int main () 19 { 20 // freopen ("a.txt" , "r" , stdin) ; 21 int cnt ; 22 int ans = 1 ; 23 bool flag ; 24 25 while (~ scanf ("%d%d" , &n , &d)) { 26 if (n == 0 && d == 0) 27 break ; 28 flag = 0 ; 29 30 for (int i = 0 ; i < n ; i++) { 31 scanf ("%lf%lf" , &a[i].x , &a[i].y) ; 32 if (a[i].y > 1.0 * d || a[i].y < 0 || d <= 0) { 33 flag = 1 ; 34 } 35 if (!flag) { 36 a[i].left = (double) a[i].x - sqrt (1.0 * d * d - a[i].y * a[i].y) ; 37 a[i].right = (double) a[i].x + sqrt (1.0 * d * d - a[i].y * a[i].y) ; 38 } 39 } 40 if (flag) { 41 printf ("Case %d: -1\n" , ans++) ; 42 continue ; 43 } 44 sort (a , a + n , cmp) ; 45 cnt = 1 ; 46 double l = a[0].left , r = a[0].right ; 47 for (int i = 1 ; i < n ; i++) { 48 if (a[i].left > r) { 49 cnt++ ; 50 l = a[i].left ; 51 r = a[i].right ; 52 } 53 else { 54 l = a[i].left ; 55 r = a[i].right < r ? a[i].right : r ; 56 } 57 } 58 printf ("Case %d: %d\n" , ans++ , cnt) ; 59 } 60 return 0 ; 61 }
别忘记每次都要跟新放radar的区间 ,orz
标签:
原文地址:http://www.cnblogs.com/get-an-AC-everyday/p/4298582.html