| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
c语言写的,贴一下#include<stdio.h>
#include<math.h>
#include<string.h>
int main(){
int n,d;
int count=0;
while(scanf("%d%d",&n,&d)!=EOF&&(n!=0||d!=0)){
int i,j,x[1005],y[1005];
int pd = 0;
int sum=1;
double l[1005],r[1005],temp,b;
count++;
for(i=0;i<n;i++){
scanf("%d%d",&x[i],&y[i]);
if(y[i]>d) pd=1;
}
if(pd==1){
printf("Case %d: -1\n", count);
}
else {
for(i=0;i<n;i++){
l[i]=x[i]-(sqrt(d*d-y[i]*y[i]));
r[i]=x[i]+(sqrt(d*d-y[i]*y[i]));
}
for (i = 1; i < n; i++) {
for (j = 0; j < n - i; j++) {
if (l[j]>l[j + 1]) {
temp = l[j];
l[j] = l[j + 1];
l[j + 1] = temp;
temp = r[j];
r[j] = r[j + 1];
r[j + 1] = temp;
}
}
}
b=r[0];
for (i = 1; i < n; i++) {
if (l[i]>b) {
b = r[i];
sum++;
}
else if (r[i] < b) {
b = r[i];
}
}
printf("Case %d: %d\n",count,sum);
}
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator