[水]POJ2431
来源:互联网 发布:修改sql语句怎么写 编辑:程序博客网 时间:2024/05/01 17:00
POJ2431
分析:
每个路过的站都可以看成是随时想加油就加油的站,用堆维护路过的站的储油量。O(nlgn)
代码
#include <iostream>#include <cstdio>#include <cstring>#include <queue>#include <algorithm>using namespace std;const int maxn = 10005;int L,P;pair<int,int> pr[maxn];int main(){ int n,res; while(~scanf("%d",&n)) { priority_queue<int> pq; res=0; for(int i=1;i<=n;i++) { scanf("%d%d",&pr[i].first,&pr[i].second); } scanf("%d%d",&L,&P); pr[0].first=0,pr[n+1].first=L; for(int i=1;i<=n;i++) { pr[i].first=L-pr[i].first; } sort(pr+1,pr+2+n); int nowpos=0,nowoil=P;//当前的位置 当前的剩余oil bool sign=0; while(1) { while(nowpos<=n&&nowoil>=pr[nowpos+1].first-pr[nowpos].first) //如果有下一个站且当前剩余oil够到下一个站 { nowoil-=pr[nowpos+1].first-pr[nowpos].first; pq.push(pr[nowpos+1].second); nowpos++; } if(nowpos>n) {sign=1;break;}//如果到达了终点则有解退出 if(pq.size()) { res++; nowoil+=pq.top(); pq.pop(); } else break;//如果无论如何也不能到达下一个站则无解退出 } if(sign) cout<<res<<endl; else cout<<-1<<endl; } return 0;}
0 0
- [水]POJ2431
- poj2431
- POJ2431
- poj2431
- poj2431
- POJ2431
- POJ2431
- poj2431 Expedition
- POJ2431 Expedition
- poj2431 Expedition
- POJ2431 Expedition
- POJ2431--Expedition
- POJ2431-Expedition
- Expetion(POJ2431)
- POJ2431 贪心
- POJ2431-Expedition
- poj2431 Expedition
- poj2431 Expedition 优先队列
- 全角与半角的转换函数
- Codeforces 534D Handshakes(贪心)
- LXC初步体验
- Java实现归并排序
- 黑马程序员_日记37_LinkedList概述及特有方法演示
- [水]POJ2431
- 多线程(四) :同步工具类 和 集合工具类
- Vxworks任务间的通信
- ubuntu14.10安装arm的qwt(2)
- 苹果审核被拒/sdk 4.2上不显示没有安装客户端的平台,友盟第三方登陆,强制安装QQ客户端,被拒绝
- Java开发之反射机制(详)
- CMOS Sensor的调试经验分享
- CSS:盒子模型与定位
- 《Kinect应用开发实战》读书笔记---干货集合