poj2431(优先队列)
来源:互联网 发布:什么叫淘宝刷流量 编辑:程序博客网 时间:2024/06/17 19:10
题目
题目:一辆车要从一个城市到另一个城市,给你距离L和出发时的汽油总量P,路上里终点
题解:将离终点距离转化为离起点距离,一直走,等汽油消耗完了之后再从前面走过的加油站中选取可加油量最大的一个,重复这样。用优先队列维护。
#include<queue>#include<cstdio>#include<algorithm>#include<cstring>using namespace std;#define ll long longconst int maxn = 1e4 + 5;priority_queue<ll> q;struct bbq{ ll a,b;};bbq x[maxn];bool cmp(bbq a, bbq b){ return a.a < b.a;}int main(){ ll n,L,P; while (~scanf("%lld",&n)) { memset(x,0,sizeof x); while(!q.empty()) { q.pop(); } for (int i = 0; i < n; i++) { scanf("%lld %lld",&x[i].a,&x[i].b); } scanf("%lld %lld",&L,&P); for (int i = 0; i < n; i++) { x[i].a = L - x[i].a; } x[n].a = L; sort(x,x+n,cmp); ll ans = 0,flag = 0; for (int i = 0; i <= n; i++) { while(P < x[i].a && !q.empty()) { P += q.top(); q.pop(); if(P < x[i].a && q.empty()) { flag = 1; break; } ans++; } if(P >= x[i].a) { q.push(x[i].b); } } if(!flag) { printf("%lld\n",ans); } else printf("-1\n"); }}
阅读全文
0 0
- poj2431 Expedition 优先队列
- 优先队列--poj2431
- POJ2431 Expedition (优先队列)
- POJ2431 数据结构 (优先队列)
- poj2431(优先队列)
- poj2431 优先队列
- poj2431优先队列
- POJ2431(优先队列)
- POJ2431优先队列
- poj2431 优先队列
- poj2431 Expedition_STL优先队列
- poj2431 优先队列
- POJ2431 优先队列+贪心
- poj2431(优先队列)
- POJ2431 优先队列
- POJ2431 Expedition(排序+优先队列)
- [POJ2431]Expedition[贪心][优先队列]
- POJ2431 运用queueq优先队列
- 测试用例中Spring+mock的值代替不确定值
- 快速计算掩码位数
- PowerDesigner使用指南
- 字符串常量到底存在哪了?
- Java Logging
- poj2431(优先队列)
- git 生成patch
- github上关于iOS的各种开源项目集合(转)
- hexdump.asm
- Android Camera 正方形预览(一)
- 使用SSH密钥连接Github【图文教程】
- 自动化DDL审核|pymysql链接Inception中踩过的几个坑
- 运行forever报command not found
- HTTP与HTTPS的区别