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

第一次 写东西 就贴代码了 16ms

Posted by ljhzxc at 2015-01-27 20:00:20 on Problem 1328
#include<stdio.h>
#include<math.h>
struct node{
	int x;
	int y;
	double left;
	double right;
}place[1010], temp;
int main()
{
	int n, d, i, j, counter = 0, min, flag, min_num;
	double _left, _right;
	//freopen("input.txt", "r", stdin);
	while (scanf("%d%d", &n, &d) == 2, n != 0 || d != 0){
		counter++;
		flag = 1;
		min_num = 0;
		for (i = 0; i<n; i++){
			scanf("%d%d", &place[i].x, &place[i].y);
			if (place[i].y>d){
				flag = 0;
			}
		}
		if (!flag || d <= 0){
			printf("Case %d: -1\n", counter);
			continue;
		}
		for (i = 0; i<n; i++){
			place[i].right = place[i].x + sqrt(d*d - place[i].y*place[i].y);
			place[i].left = place[i].x - sqrt(d*d - place[i].y*place[i].y);
		}
		for (i = 0; i<n - 1; i++){
			min = i;
			for (j = i + 1; j<n; j++)
				if (place[j].left<place[min].left)
					min = j;
			if (min != i){
				temp = place[min];
				place[min] = place[i];
				place[i] = temp;
			}
		}
		for (i = 0; i<n; min_num++){
			_right = place[i].right;
			_left = place[i++].left;
			while (i<n && place[i].left <= _right){
				_left = _left>place[i].left ? _left : place[i].left;
				_right = _right<place[i].right ? _right : place[i].right;
				i++;
			}
		}
		printf("Case %d: %d\n", counter, min_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