标签:ges term one efi represent space eve image any
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
题解:贪心
按x从小到大排序
首先是要卡边界
对于当前点,如果能被之前的覆盖就直接覆盖
如果不能,那么如果覆盖当前点的圆心(能覆盖到的最右端)的横坐标小于当前圆心横坐标,那么就更新当前圆心坐标,否则ans++
1 #include<iostream> 2 #include<cstdio> 3 #include<cstdlib> 4 #include<cstring> 5 #include<algorithm> 6 #include<cmath> 7 #define ll long long 8 using namespace std; 9 10 const int N = 1010; 11 12 int n,d,ans,tot,flg; 13 double pos; 14 15 struct Node { 16 double x,y; 17 bool operator < (const Node a) const { 18 return x<a.x; 19 } 20 }p[N]; 21 22 int gi() { 23 int x=0,o=1; char ch=getchar(); 24 while(ch!=‘-‘ && (ch<‘0‘ || ch>‘9‘)) ch=getchar(); 25 if(ch==‘-‘) o=-1,ch=getchar(); 26 while(ch>=‘0‘ && ch<=‘9‘) x=x*10+ch-‘0‘,ch=getchar(); 27 return o*x; 28 } 29 30 int main() { 31 while(scanf("%d%d", &n, &d) && n+d) { 32 ans=1,tot++,flg=0; 33 for(int i=1; i<=n; i++) { 34 p[i].x=gi(),p[i].y=gi(); 35 } 36 for(int i=1; i<=n; i++) { 37 if(p[i].y>d) {flg=1;break;} 38 } 39 if(flg) {printf("Case %d: %d\n",tot,-1);continue;} 40 sort(p+1,p+n+1); 41 pos=p[1].x+sqrt(d*d-p[1].y*p[1].y); 42 for(int i=2; i<=n; i++) { 43 if((pos-p[i].x)*(pos-p[i].x)+p[i].y*p[i].y<=d*d) continue; 44 double pos1=p[i].x+sqrt(d*d-p[i].y*p[i].y); 45 if(pos1>pos) ans++; 46 pos=pos1; 47 } 48 printf("Case %d: %d\n",tot,ans); 49 } 50 return 0; 51 }
标签:ges term one efi represent space eve image any
原文地址:http://www.cnblogs.com/HLXZZ/p/7502712.html