| ||||||||||
| 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 | |||||||||
简单的优先队列#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator