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
欢迎报名第四届北京大学游戏对抗邀请赛!

break导致Runtime Error

Posted by HuaSir at 2018-10-10 09:28:42 on Problem 1328
代码片段:
for (int i = 0; i < n; ++i)
{
	double x, y;
	cin>>x>>y;
	if (y > d){
		ans = -1;
		break;//导致Runtime Error
	}
	offset = sqrt(d*d - y*y);
	range[i].l = x - offset;
	range[i].r = x + offset;		
}
输入时若发现某小岛y值大于雷达范围就break,输出-1,但这样却会导致Runtime Error,不知为何,哪位大佬能解答一下?
整体代码:
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
using namespace std;

struct ran{
	double l;
	double r;
}range[1000];

int cmp(const void *a, const void *b){
	return ((*(ran *)a).l > (*(ran *)b).l)?1:-1;
}

int main()
{
	double offset, a, d;
	int t=1;
	int ans, n;
	while (cin>>n>>d && n && d){
		ans = 1;
		for (int i = 0; i < n; ++i)
		{
			double x, y;
			cin>>x>>y;
			if (y > d){
				ans = -1;
				//break;//导致Runtime Error
			}
			offset = sqrt(d*d - y*y);
			range[i].l = x - offset;
			range[i].r = x + offset;		
		}
		if (ans != -1){
		    qsort(range, n, sizeof(range[0]), cmp);
			a = range[0].r;
			for (int i = 1; i < n; ++i)
			{
				if (range[i].l > a){
					a = range[i].r;
					ans++;
				}else if (range[i].r < a){
					a = range[i].r;
				}
			}
		}
		printf("Case %d: %d\n", t++, ans);
	}
	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