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 |
大家帮我看看 为什么 总是提示Rumtime Error?#include <iostream> #include <cmath> #include <algorithm> #include <stdio.h> #define min(a,b) ((a)<(b)?(a):(b)) using namespace std; struct scope { double left; double right; } sscope[1000]; int cmp(struct scope x, struct scope y) { return x.left < y.left ? 1 : 0; } int main() { int n = 0, i = 0, cas = 1, omit = 0, count = 1; double location = 0 , r = 0, x = 0, y = 0; while (scanf("%d %lf", &n, &r)) { if (n == 0 && r == 0) break; i = 0; omit = 0; while (i < n) { scanf("%lf %lf", &x, &y); if (y > r) { printf("Case %d: -1\n", cas); omit = 1; break; } sscope[i].left = x - sqrt(pow(r, 2) - pow(y, 2)); sscope[i].right = x + sqrt(pow(r, 2) - pow(y, 2)); i++; } if (omit != 1) { sort(sscope, sscope + n, cmp); for (i = 0, count = 1; i < n - 1; i++) { location = sscope[i].right; if (location < sscope[i + 1].left) { count++; location = sscope[i].right; } else location = min(sscope[i+1].right, location); } printf("Case %d: %d\n", cas, count); cas++; } } } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator