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) 有三种运动方式: ...
随机推荐
- innoback 参数及使用说明
--defaults-file 同xtrabackup的--defaults-file参数,指定mysql配置文件; --apply-log 对xtrabackup的--prepare参数的封装; - ...
- python list常见用法
来至builtins.py: def extend(self, iterable): # real signature unknown; restored from __doc__ "&qu ...
- 06-struts2与ognl的结合
1 参数接收 2 配置文件中 1 Demo2Action package www.test.c_config; import com.opensymphony.xwork2.ActionSupport ...
- [Matlab] fprintf
%s format as a string%d format with no fractional part (integer format)%f format as a oating-point v ...
- bzoj 5298: [Cqoi2018]交错序列
Description 我们称一个仅由0.1构成的序列为"交错序列",当且仅当序列中没有相邻的1(可以有相邻的0).例如,000,001 ,101,都是交错序列,而110则不是.对 ...
- 弱类型dynamic与var
dynamic与var都可代替任何类型 var关键字是C# 3.0开始新增的特性,称为推断类型. 1.必须在定义时初始化 2.一但初始化完成就不能再给变量赋与初始化值类型不同的值 3.var要求是局部 ...
- vs文件属性(复制到输出目录)是什么意思
右击项目里的文件,选择属性(F4)会有复制到输出目录的选项. 它提供三项选择,如图: 如果选择始终复制或如果较新则复制会在该程序集的bin目录下生成该文件,如图:
- node express formidable 文件上传后修改文件名
//我是用php的思想来学习nodejs var express = require('express'); var router = express.Router(); var fs = requi ...
- Csharp: TreeView 初始化设置默认选择节点
/// <summary> /// 设置查找的节点为选定节点 /// 涂聚文 /// 2013-07-15 /// </summary> /// <param name= ...
- vs2010的帮助文档
系统重装了,发现vs2010的帮助无论如何都是web方式,这种体验很差劲. google了才明白,原来是ms发展过程的一个败笔. 需要升级到vs2010 sp1才会有跟以前一样的帮助系统. 彻底无语了 ...