Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
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;
}

#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: