嘟嘟嘟

水贪心。

当经过一个加油站的时候,记下这个加油站能加的油,然后没油的时候从经过的加油站中选择加油最多的加。

 #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的更多相关文章

  1. EXPEDI - Expedition 优先队列

    题目描述 A group of cows grabbed a truck and ventured on an expedition deep into the jungle. Being rathe ...

  2. 题解 P1016 旅行家的预算

    题目传送门(以纪念调了两个半小时的单调队列) emmm这题单调队列可海星... 因为每个点有油量无限的,但是油箱容量是无限的(正好反的一道题 SP348 EXPEDI - Expedition) 所以 ...

  3. POJ 2431 Expedition(优先队列、贪心)

    题目链接: 传送门 Expedition Time Limit: 1000MS     Memory Limit: 65536K 题目描述 驾驶一辆卡车行驶L单位距离.最开始有P单位的汽油.卡车每开1 ...

  4. POJ 2431 Expedition(探险)

    POJ 2431 Expedition(探险) Time Limit: 1000MS   Memory Limit: 65536K [Description] [题目描述] A group of co ...

  5. poj 2431 Expedition

    Expedition Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 12980   Accepted: 3705 Descr ...

  6. POJ 2431 Expedition (STL 优先权队列)

    Expedition Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8053   Accepted: 2359 Descri ...

  7. Expedition(优先队列)

    Expedition 点我 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9465   Accepted: 2760 Des ...

  8. poj 3431 Expedition 优先队列

    poj 3431 Expedition 优先队列 题目链接: http://poj.org/problem?id=2431 思路: 优先队列.对于一段能够达到的距离,优先选择其中能够加油最多的站点,这 ...

  9. CF1091F New Year and the Mallard Expedition

    题目地址:CF1091F New Year and the Mallard Expedition 题意比较复杂,整理一下: \(n\) 段,每段有两个属性:长度,地形(G,W,L) 有三种运动方式: ...

随机推荐

  1. VUE--mixins的一些理解。

    概念:混入 (mixins) 是一种分发 Vue 组件中可复用功能的非常灵活的方式.混入对象可以包含任意组件选项.当组件使用混入对象时,所有混入对象的选项将被混入该组件本身的选项. 用法: 1.创建混 ...

  2. Hash算法总结

    1. Hash是什么,它的作用 先举个例子.我们每个活在世上的人,为了能够参与各种社会活动,都需要一个用于识别自己的标志.也许你觉得名字或是身份证就足以代表你这个人,但是这种代表性非常脆弱,因为重名的 ...

  3. mac下安装ionic

    我的mac系统是EI Capitan,如下图所示. ionic是一个跨平台的框架,能够提供高效hybrid app的开发,而且性能接近于原生态,具体请参考:http://ionicframework. ...

  4. adb调试安卓

    http://blog.csdn.net/liushida00/article/details/49797239

  5. 动态替换animator的研究

    http://blog.csdn.net/tonnychu/article/details/49903657 http://blog.csdn.net/tlrainty/article/details ...

  6. 【原】shell编写一个简单的jmeter自动化压测脚本

    在公司做压力测试也挺长时间了,每次测试前环境数据准备都需要话费较长时间,所以一直在考虑能不能将整个过程实现自动化进行,于是就抽空写了一个自动化脚本,当然这个脚本目前功能十分简陋,代码也不完善,很有很多 ...

  7. Oracle关于All和Any

    简单的说 All等价于N个And语句,Any等价于N个or语句.

  8. CTPN_论文阅读总结

    论文全名:Detecting Text in Natural Image with Connectionist Text Proposal Network 1.摘要 (1)本文提出新型网络CTPN,用 ...

  9. Mysql5.7的安装配置问题

    前些日子安装和配置mysql,遇到一些问题,在这里记录一下. 1.首先,把zip的mysql解压. 2.设置环境变量PATH中添加你的mysql解压目录. 3.在mysql根目录下新建my.ini文件 ...

  10. oracle学习篇一:sqlplus常用命令

    1.程序运行--> cmd --> sqlplus 登陆普通用户:scott/brant;普通管理员用户登陆:system/brant;高级管理员用户登陆:1>先切换其他用户:SQL ...