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

为什么总是wa,帮帮忙看下

Posted by zhangyiviva at 2012-05-23 17:34:43 on Problem 2431
//
//  main.cpp
//  poj2431
//
//  Created by zhangyi zhang on 12-5-23.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#include <iostream>
#include <queue>
#include <algorithm>

using namespace std;

int a[10001];
int b[10001];

bool cmp(int a, int b)
{
    return a>b;
}



int main(int argc, const char * argv[])
{
    int n,l,p,dis;
    int ans = 0;
    int index = 0;
    priority_queue<int> queue;
    
    cin>>n;
    for(int i=0; i<n; i++)
        cin>>a[i]>>b[i];
    cin>>l>>p;
    sort(a,a+n,cmp);
    sort(b,b+n,cmp);
    dis = l;
    queue.push(p);
    
    while(index<n)
    {
        if(b[index]<=l)
            break;
        index++;
    }
    
    while(dis > 0)
    {
        for(; a[index]>=dis && index <n; index++)
            queue.push(b[index]);
        if(queue.empty())
        {
            cout<<-1<<endl;
            return 1;
        }
        dis -= queue.top();
        queue.pop();
        ans++;
    }
    
    cout<<ans-1<<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