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

补充一个数据

Posted by yuheyang_949 at 2025-01-18 10:07:31 on Problem 1328
2 5
-1 5
100 2

Case 1: 2

#### 错误代码
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
const int N = 1010;
struct Island{
	double s, e;
} islands[N];
bool cmp(Island x, Island y)
{
	return x.e < y.e;
}
int main()
{
	
//	freopen("input.txt", "r", stdin); 
	int n;
	double d;
	int c_num = 0;
	while(scanf("%d%lf", &n, &d) == 2)
	{
		c_num ++ ;
		if(n == 0 && d == 0) return 0;
		bool is_continue = false;
		if(d < 0) is_continue = true;
		for(int i = 0; i < n; i ++)
		{
			double x, y;
			scanf("%lf%lf", &x, &y);
			if(d < y || y < 0) is_continue = true;
			if(is_continue) continue;
				double temp =sqrt(d * d - y * y); 
				islands[i].s = x - temp;
				islands[i].e = x + temp;
		}
		if(is_continue)
		{
			printf("Case %d: %d\n", c_num, -1);
			continue;
		}
		sort(islands, islands + n, cmp);
		double e = islands[0].e;
		int ans = 1;
		for(int i = 0; i < n; i ++)
		{
			if(islands[i].s > e)
			{
				ans ++;
				e = islands[i].e;
			}
		}
//		double e = islands[0].e;
//		int ans = 1;
//		for(int i = 0; i < n; i ++)
//		{
//			if(islands[i].s > e)
//			{
//				ans ++;
//				e = islands[i].e;
//			}
//		}
		printf("Case %d: %d\n", c_num, ans);
	}
	return 0;
}

#### 错误思路
根据每个岛的y坐标和雷达半径求出扫描到该岛的雷达在x轴上的安装范围[s, e],程序中的s,和e初始化-1,当求出的范围也为s和e恰好也为-1时发生错误.

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