Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

c语言写的,贴一下

Posted by MrGaozhong at 2018-09-14 16:05:32 on Problem 1328
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator