Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

重金悬赏此代码为何不能AC的原因,试了一晚上了

Posted by 10132130155 at 2016-09-20 21:41:03 on Problem 1328
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator