SP348 EXPEDI - Expedition
水贪心。
当经过一个加油站的时候,记下这个加油站能加的油,然后没油的时候从经过的加油站中选择加油最多的加。
#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<vector>
#include<stack>
#include<queue>
using namespace std;
#define enter puts("")
#define space putchar(' ')
#define Mem(a, x) memset(a, x, sizeof(a))
#define rg register
typedef long long ll;
typedef double db;
const int INF = 0x3f3f3f3f;
const db eps = 1e-;
const int maxn = 1e4 + ;
inline ll read()
{
ll ans = ;
char ch = getchar(), last = ' ';
while(!isdigit(ch)) {last = ch; ch = getchar();}
while(isdigit(ch)) {ans = ans * + ch - ''; ch = getchar();}
if(last == '-') ans = -ans;
return ans;
}
inline void write(ll x)
{
if(x < ) x = -x, putchar('-');
if(x >= ) write(x / );
putchar(x % + '');
} int n;
struct Node
{
int d, val;
bool operator < (const Node &oth)const
{
return d < oth.d;
}
}t[maxn]; priority_queue<int> q; int main()
{
int T = read();
while(T--)
{
while(!q.empty()) q.pop();
n = read();
for(int i = ; i <= n; ++i) t[i].d = read(), t[i].val = read();
int dis = read(), p = read();
for(int i = ; i <= n; ++i) t[i].d = dis - t[i].d;
sort(t + , t + n + );
int now = , ans = ;
bool flg = ;
int i = ;
while(now < dis)
{
while(p - t[i].d + now >= && i <= n)
{
p = p - t[i].d + now, now = t[i].d;
q.push(t[i].val);
i++;
}
if(now + p >= dis) break;
if(q.empty()) {flg = ; break;}
p += q.top(); q.pop(); ans++;
}
if(!flg) puts("-1");
else write(ans), enter;
}
return ;
}
SP348 EXPEDI - Expedition的更多相关文章
- EXPEDI - Expedition 优先队列
题目描述 A group of cows grabbed a truck and ventured on an expedition deep into the jungle. Being rathe ...
- 题解 P1016 旅行家的预算
题目传送门(以纪念调了两个半小时的单调队列) emmm这题单调队列可海星... 因为每个点有油量无限的,但是油箱容量是无限的(正好反的一道题 SP348 EXPEDI - Expedition) 所以 ...
- POJ 2431 Expedition(优先队列、贪心)
题目链接: 传送门 Expedition Time Limit: 1000MS Memory Limit: 65536K 题目描述 驾驶一辆卡车行驶L单位距离.最开始有P单位的汽油.卡车每开1 ...
- POJ 2431 Expedition(探险)
POJ 2431 Expedition(探险) Time Limit: 1000MS Memory Limit: 65536K [Description] [题目描述] A group of co ...
- poj 2431 Expedition
Expedition Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 12980 Accepted: 3705 Descr ...
- POJ 2431 Expedition (STL 优先权队列)
Expedition Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8053 Accepted: 2359 Descri ...
- Expedition(优先队列)
Expedition 点我 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9465 Accepted: 2760 Des ...
- poj 3431 Expedition 优先队列
poj 3431 Expedition 优先队列 题目链接: http://poj.org/problem?id=2431 思路: 优先队列.对于一段能够达到的距离,优先选择其中能够加油最多的站点,这 ...
- CF1091F New Year and the Mallard Expedition
题目地址:CF1091F New Year and the Mallard Expedition 题意比较复杂,整理一下: \(n\) 段,每段有两个属性:长度,地形(G,W,L) 有三种运动方式: ...
随机推荐
- python查看模块版本及所在文件夹
# 以Numpy为例 第一种方法:import numpy as np np.__version__ >>> '1.12.1' np.__file__ >>> '/ ...
- MongoDB数据库进阶 --- 增删查改...
注意: monogdb数据在使用之后必须及时 mongodb.close()否则后台崩溃. 在之前的文章中,我已经介绍了什么事MongoDB以及怎么在windows下安装MongoDB等等基本知识. ...
- POJ 2570 Fiber Network
Description Several startup companies have decided to build a better Internet, called the "Fibe ...
- java多线程之线程组与线程池
看这篇文章:http://blog.csdn.net/zen99t/article/details/50909099
- 九度oj题目1511:从尾到头打印链表
题目1511:从尾到头打印链表 时间限制:1 秒 内存限制:128 兆 特殊判题:否 提交:6010 解决:1805 题目描述: 输入一个链表,从尾到头打印链表每个节点的值. 输入: 每个输入文件仅包 ...
- 整理代码,将一些曾经用过的功能整合进一个spring-boot
一 由于本人的码云太多太乱了,于是决定一个一个的整合到一个springboot项目里面. 附上自己的项目地址https://github.com/247292980/spring-boot 功能 1. ...
- 数据从mysql迁移到hbase的一些思考及设计
一.进行迁移的原因 由于业务的发展,使用mysql进行建立索引进行搜索已经造成数据流的瓶颈卡在了数据库io,例如每次dump全表的时候,会造成压力过大,造成耗时很长,并且当前的数据量基本上已经达到了亿 ...
- SQLite 大小写敏感
--转自mojianpo http://mojianpo.iteye.com/blog/1496579 大部分数据库在进行字符串比较的时候,对大小写是不敏感的. 但是,在SQLite中,对大小写是敏 ...
- JS && || 陷阱 javascript 逻辑与、逻辑或 【转】
通常来说逻辑运算a&&b和a||b分别是逻辑与运算和逻辑或运算,返回的是一个布尔值,要么为true,要么为false. 比如在PHP里面a&&b返回类型永远是布尔值,非 ...
- div居中方法总结
在日常开发过程中,我们会经常使用到div居中来处理布局,今天我就把我在开发过程中,遇到的div居中处理方法总结一下,方便日后查看! 1. 水平居中:给div设置一个宽度,然后添加marg ...