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 |
重金悬赏此代码为何不能AC的原因,试了一晚上了#include <cstdio> #include <cstdlib> #include <cmath> #include <algorithm> #include <iostream> #define MAXN 1010 using namespace std; struct Node { double x, y; double left, right; // bool operator < (const Node &a) const { // return ((left < a.left) || (left == a.left && right <= a.right)); // } }; Node record[MAXN]; int cmp(Node a,Node b) { return a.left<b.left || (a.left==b.left && a.right<=b.right); } // bool cmp(Node a, Node b){ // if( b.right - a.right > 10e-7){ // return true; // } // if(abs(a.right - b.right) < 10e-7 && ( b.left - a.left > 10e-7)){ // return true; // } // return false; // } int main() { int n, t = 1, d; while (scanf("%d %d", &n, &d) != EOF) { if (n == 0 && d == 0) break; int tag = 0; if (d <= 0) tag = 1; for (int i = 0; i < n; i++) { scanf("%lf %lf", &record[i].x, &record[i].y); if (record[i].y > d) tag = 1; double tmp = sqrt(d*d*1.0-record[i].y*record[i].y); record[i].left = 1.0*record[i].x-tmp; record[i].right = 1.0*record[i].x+tmp; } if (tag == 1) { printf("Case %d: -1\n", t++); continue; } sort(record, record+n, cmp); int cnt = 1; int curr = record[0].right; for (int i = 1; i < n; i++) { if (curr < record[i].left) { curr = record[i].right; cnt++; } else if (curr > record[i].right) { curr = record[i].right; } } printf("Case %d: %d\n", t++, cnt); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator