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 思路: 优先队列.对于一段能够达到的距离,优先选择其中能够加油最多的站点,这 ...
随机推荐
- CStdioFile UNICODE编译 读取中文汉字乱码 .
函数原形为:char *setlocale( int category, const char *locale );头文件:<locale.h>所支持的操作系统为:ANSI, Win 95 ...
- poj 3683(2-sat+输出一组可行解)
题目链接:http://poj.org/problem?id=3683 思路:对于每个结婚仪式,只有在开始或结束时进行这两种选择,我们可以定义xi为真当且仅当在开始时进行.于是我们可以通过时间先后确定 ...
- python3----split and join
s = "I am fine" s = s.split(" ") print(s) print("%".join(s)) results: ...
- python各种库、框架的安装和卸载
才疏学浅,努力深入,逐步更新,有问题敬请留言告知,谢谢. 关于python第三方库的安装最好少使用 easy_install,因为 easy_install 只能安装不能卸载,如果要卸载需要进入到 p ...
- Android无线测试之—UiAutomator UiObject API介绍一
UiObject类介绍 一.UiObject类介绍 UiObject代表一个UI元素,通过UiSelector查找跳进创建一个UiObject实例,找到这个实例以后可以对这个实例进行各类操作 二.Ui ...
- 导出大量数据到excel表
set_time_limit(0);error_reporting(0); // 输出Excel文件头,可把user.csv换成你要的文件名header('Content-Type: applicat ...
- 【转】10 个MySQL数据库备份教程推荐
10 个MySQL数据库备份教程推荐 MySQL是动态网站开发中最著名的开源数据库系统.如果你在网站中使用了MySQL,那么你应该定期备份你的数据以防止它丢失. 本文将介绍自动或手动备份MySQL数据 ...
- 【BZOJ3444】最后的晚餐 乱搞
[BZOJ3444]最后的晚餐 Description [问题背景] 高三的学长们就要离开学校,各奔东西了.某班n人在举行最后的离别晚餐时,饭店老板觉得十分纠结.因为有m名学生偷偷找他,要求和自己暗恋 ...
- redo binlog
w https://dev.mysql.com/doc/refman/5.7/en/innodb-redo-log.html https://dev.mysql.com/doc/refman/5.7/ ...
- 处理 Java 的“Cannot allocate memory”错误
今天在配置 DCA 服务器的时候,检验 java 版本的时候忽然遇到了一个 Cannot allocate memory 错误 [root@elcid-prod1 ~]# java -version ...