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

简单的优先队列

Posted by CCUT_king at 2018-02-22 13:41:11 on Problem 2431 and last updated at 2018-02-22 13:41:37
#include <iostream>
#include <queue>
#include <algorithm>
const int maxn=10005;
/*优先队列*/
using namespace std;
typedef pair<int,int> pp;
pp node[maxn];      //存加油站
priority_queue<int> que;
bool cmp(pp x,pp y)
{
    return x.first>y.first;//距离起点近的排序
}
int main()
{
    int n,l,p,i=0,cnt=0;
    cin >> n;
    for(int i=0;i<n;i++)
        cin >> node[i].first >> node[i].second;
    sort(node,node+n,cmp);
    cin >> l >> p;
    while(p<l)
    {
        for(;i<n;i++)
        {
            if(l-node[i].first<=p)
                que.push(node[i].second);
            else
                break;
        }
        if(!que.empty())
        {
            p+=que.top(); //能行驶的最大距离;
            cnt++;
            que.pop();
        }else
        {
            cout << -1 << endl;
            return 0;
        }
    }
    cout << cnt << 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