Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
break导致Runtime Error代码片段: 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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator