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

注意平方爆整形。事先转换成doulbe吧

Posted by KatrineYang at 2016-09-11 21:03:29 on Problem 1328
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <algorithm>
using namespace std;

int N, d;

struct intv{
	double s, e;
}intvs[1005];

bool compare(const intv &i1, const intv &i2){
	return i1.e < i2.e;
}

int main() {
	int cnt = 0;
	while(1){
		scanf("%d%d", &N, &d);
		if(N==0 && d==0) return 0;
		cnt++;
		printf("Case %d: ", cnt);
		bool rrky = 1;
		if(d < 0) rrky = 0;
		for(int i = 0; i < N; i++){
			int x, y;
			scanf("%d%d", &x, &y);
			if(abs(y+0.0) > d) rrky = 0;
			if(rrky){
				double sqt = sqrt(0.0+d*1.0*d-y*1.0*y);
				intvs[i].s = x-sqt, intvs[i].e = x+sqt;
			}
		}
		if(!rrky){
			printf("-1\n");
			continue;
		}
		sort(intvs, intvs+N, compare);
		int num = 0;
		double curPos = -1e300;
		for(int i = 0; i < N; i++){
			if(curPos < intvs[i].s){
				num++;
				curPos = intvs[i].e;
			}
		}
		printf("%d\n", num);
	}
	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