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 |
第一次 写东西 就贴代码了 16ms#include<stdio.h> #include<math.h> struct node{ int x; int y; double left; double right; }place[1010], temp; int main() { int n, d, i, j, counter = 0, min, flag, min_num; double _left, _right; //freopen("input.txt", "r", stdin); while (scanf("%d%d", &n, &d) == 2, n != 0 || d != 0){ counter++; flag = 1; min_num = 0; for (i = 0; i<n; i++){ scanf("%d%d", &place[i].x, &place[i].y); if (place[i].y>d){ flag = 0; } } if (!flag || d <= 0){ printf("Case %d: -1\n", counter); continue; } for (i = 0; i<n; i++){ place[i].right = place[i].x + sqrt(d*d - place[i].y*place[i].y); place[i].left = place[i].x - sqrt(d*d - place[i].y*place[i].y); } for (i = 0; i<n - 1; i++){ min = i; for (j = i + 1; j<n; j++) if (place[j].left<place[min].left) min = j; if (min != i){ temp = place[min]; place[min] = place[i]; place[i] = temp; } } for (i = 0; i<n; min_num++){ _right = place[i].right; _left = place[i++].left; while (i<n && place[i].left <= _right){ _left = _left>place[i].left ? _left : place[i].left; _right = _right<place[i].right ? _right : place[i].right; i++; } } printf("Case %d: %d\n", counter, min_num); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator