原来做过的贪心
比较简单
View Code
1 #include <stdio.h> 2 #include <string.h> 3 #include <math.h> 4 #include <algorithm> 5 using namespace std; 6 struct node 7 { 8 int x,y; 9 }il[10005]; 10 struct re 11 { 12 double x1,x2; 13 }radar[10005]; 14 int cmp(struct re a,struct re b) 15 { 16 return a.x2 < b.x2; 17 } 18 int main() 19 { 20 int i,n,cas = 0; 21 int d; 22 while(scanf("%d %d",&n,&d) && n||d) 23 { 24 25 int leap; 26 leap = 1; 27 for(i = 0;i < n;i++) 28 { 29 scanf("%d %d",&il[i].x,&il[i].y); 30 radar[i].x1 = il[i].x-sqrt(1.0*d*d-il[i].y*il[i].y); 31 radar[i].x2 = il[i].x+sqrt(1.0*d*d-il[i].y*il[i].y); 32 if(il[i].y - d > 0 ) 33 leap = 0; 34 } 35 if(!leap) 36 { 37 printf("Case %d: -1\n",++cas); 38 continue; 39 } 40 sort(radar,radar+n,cmp); 41 int ans; 42 double pre; 43 ans = 1; 44 pre = radar[0].x2; 45 for(i = 1;i < n;i++) 46 { 47 if(pre < radar[i].x1) 48 pre = radar[i].x2,ans++; 49 } 50 printf("Case %d: %d\n",++cas,ans); 51 52 53 54 } 55 }