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

Re:为什么 总是提示Rumtime Error? 楼主数据和补充数据都过了

Posted by 648892238 at 2017-05-24 12:16:16 on Problem 1328 and last updated at 2017-05-24 12:17:17
In Reply To:Re:大家帮我看看 为什么 总是提示Rumtime Error? Posted by:648892238 at 2017-05-24 12:14:48

#include <iostream>
#include <algorithm>
#include <math.h>
#include <list>
using namespace std;
typedef struct section{
    double left;
    double right;
}Section;
int n,d;
int cmp(Section a,Section b){
    if (a.right<b.right) {
        return 1;
    }
    return 0;
}
int main(int argc, const char * argv[]) {
    int cou = 0;
    while (1) {
        cin>>n>>d;
        if (n==0&&d==0) {
            break;
        }
        cou++;
        list<Section> t;
        double a,b;
        int ok = 1;
        for(int i=0;i<n;i++){
            cin>>a>>b;
            if (d<0) {
                ok = 0;
                continue;
            }
            double l = d*d-b*b;
            if (l<0) {
                ok = 0;
                continue;
            }else{
                l = sqrt(l);
                Section item;
                item.left = a-l;
                item.right = a+l;
                t.push_back(item);
            }
        }
        if (ok==0) {
            cout<<"Case "<<cou<<": -1"<<endl;
            continue;
        }
        if (n==0) {
            cout<<"Case "<<cou<<": 0"<<endl;
            continue;
        }
        int min = 1;
        t.sort(cmp);
        int R = t.front().right;
        t.erase(t.begin());
        while (!t.empty()) {
            for (list<Section>::iterator it = t.begin(); it!=t.end(); it++) {
                if ((*it).left<=R) {
                    t.erase(it);
                }
            }
            if (!t.empty()) {
                min++;
                R=t.front().right;
                t.erase(t.begin());
            }
        }
        cout<<"Case "<<cou<<": "<<min<<endl;
    }
    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