标签:
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<cstdio> #include<cstring> #include<algorithm> #include<cmath> using namespace std; const int maxn = 1000; struct X{ double left; double right; }dp[maxn]; int x[maxn],y[maxn]; bool cmp(X i,X j){ return i.left<j.left;} int main(){ int n,d,i, flag1 = 1; while(~scanf("%d%d",&n,&d)&&n&&d){ int flag2 = 0; for( i = 1; i <= n ; i++){ scanf("%d%d",&x[i],&y[i]); if(y[i] > d||d<0||y[i]<0) flag2 = 1; dp[i].left = x[i] - sqrt((double)(d*d-y[i]*y[i])); dp[i].right = x[i] + sqrt((double)(d*d-y[i]*y[i])); } if(flag2 == 1) { printf("Case %d: -1\n",flag1); flag1++; continue;} sort(dp+1,dp+n+1,cmp); int ax = 1,flag = 1; for(i = ax + 1; i <= n ; i++){ if(dp[i].right < dp[ax].right){ ax = i; } else if(dp[i].left > dp[ax].right){ ax = i; flag++; } } printf("Case %d: %d\n",flag1,flag); flag1++; } return 0; }
标签:
原文地址:http://www.cnblogs.com/zero-begin/p/4313139.html