POJ 2431 贪心+优先队列
#include<cstdio>
#include<queue>
#include<algorithm>
using namespace std;
priority_queue<int> que;
struct Stop {
int dis,fuel;
}stop[];
bool cmp (Stop a,Stop b) {
if(a.dis==b.dis) return a.fuel>b.fuel;
return a.dis<b.dis;
}
int main() {
int n,L,p;
while(~scanf("%d",&n)) {
for(int i=;i<n;i++) {
scanf("%d%d",&stop[i].dis,&stop[i].fuel);
}
scanf("%d%d",&L,&p);
for(int i=;i<n;i++) {
stop[i].dis=L-stop[i].dis;
}
sort(stop,stop+n,cmp);
stop[n].dis=L;stop[n].fuel=;
int cnt=,pos=,flag=;
for(int i=;i<=n;i++) {
int d=stop[i].dis-pos;
while(p<d) {
if(!que.empty()) {
p+=que.top();
que.pop();
cnt++;
}else break;
}
if(p<d) {
flag=;
puts("-1");break;
}
p-=d;
que.push(stop[i].fuel);
pos=stop[i].dis;
}
if(flag==) printf("%d\n",cnt);
while(!que.empty()) que.pop();
}
return ;
}
POJ 2431 贪心+优先队列的更多相关文章
- poj 2431 【优先队列】
poj 2431 Description A group of cows grabbed a truck and ventured on an expedition deep into the jun ...
- Stall Reservations(POJ 3190 贪心+优先队列)
Stall Reservations Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4434 Accepted: 158 ...
- POJ 2431 (优先队列)
题目链接:https://vjudge.net/problem/POJ-2431 思路: “ 在卡车行驶途中, 只有经过加油站才能加油.” 我们不妨转变思路, 理解成“当卡车驶过加油站时就获得了加油的 ...
- poj 3190 贪心+优先队列优化
Stall Reservations Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4274 Accepted: 153 ...
- POJ 2431 Expedition (贪心+优先队列)
题目地址:POJ 2431 将路过的加油站的加油量放到一个优先队列里,每次当油量不够时,就一直加队列里油量最大的直到能够到达下一站为止. 代码例如以下: #include <iostream&g ...
- POJ 2431 优先队列
汽车每过一单位消耗一单位油,其中有给定加油站可加油,问到达终点加油的最小次数. 做法很多的题,其中优先对列解这题是很经典的想法,枚举每个加油站,判断下当前油量是否小于0,小于0就在前面挑最大几个直至油 ...
- POJ 2431 Expedition(探险)
POJ 2431 Expedition(探险) Time Limit: 1000MS Memory Limit: 65536K [Description] [题目描述] A group of co ...
- poj 1862 Stripies/优先队列
原题链接:http://poj.org/problem?id=1862 简单题,贪心+优先队列主要练习一下stl大根堆 写了几种实现方式写成类的形式还是要慢一些... 手打的heap: 1: #inc ...
- poj 3431 Expedition 优先队列
poj 3431 Expedition 优先队列 题目链接: http://poj.org/problem?id=2431 思路: 优先队列.对于一段能够达到的距离,优先选择其中能够加油最多的站点,这 ...
随机推荐
- JNI动态库生成、编译、查看相关简易资料
有一篇好博文,大家可以看下http://www.cnblogs.com/zhangweia/archive/2010/09/16/1828176.html,我这里是参考其做的另外一个javah -cl ...
- OpenCV学习笔记十二:opencv_video模块
一,简介: 该库用于视频运动分析,目标追踪,背景分离等.
- 10道mysql查询语句面试题
1.https://www.yanxurui.cc/posts/mysql/10-sql-interview-questions/ 2.http://mm.fancymore.com/reading/ ...
- 使用jenkins进行Android的持续集成
关于持续集成的定义和意义可以参考它的 百度百科 主要意义有以下几点: 减少风险 减少重复过程 任何时间.任何地点生成可部署的软件 增强项目的可见性 建立团队对开发产品的信心 持续集成的实施 持续集成的 ...
- iOS学习笔记(三)——iOS系统架构
iOS的系统架构分为四个层次:核心操作系统层(Core OS layer).核心服务层(Core Services layer).媒体层(Media layer)和可触摸层(Cocoa Touch l ...
- 【BZOJ2770】YY的Treap 结论+线段树
[BZOJ2770]YY的Treap Description 志向远大的YY小朋友在学完快速排序之后决定学习平衡树,左思右想再加上SY的教唆,YY决定学习Treap.友爱教教父SY如砍瓜切菜般教会了Y ...
- 【BZOJ3029】守卫者的挑战 概率+背包
[BZOJ3029]守卫者的挑战 Description 打开了黑魔法师Vani的大门,队员们在迷宫般的路上漫无目的地搜寻着关押applepi的监狱的所在地.突然,眼前一道亮光闪过.“我,Nizem, ...
- asp.net mvc4连接mysql
环境:vs2013+mysql5.6+mysql connector for .net 6.8.3+MySQL for Visual Studio 1.1.3 参考:http://dev.mysql. ...
- <2013 12 17> 雅思写作、口语相关
这一个多月,参加了两次雅思考试,成绩分别为: Overall:6.5 L:7.0 R:7.5 W:6.0 S:5.5 Overall:7.0 L:7.0 ...
- POCO c++ 使用例子
.定时器 #include "Poco/Timer.h" #include "Poco/Thread.h" using Poco::Timer; using P ...