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) 有三种运动方式: ...
随机推荐
- redis API ---python
一, 安装配置 必须安装python3以上 配置文件自己下载,搜索名字百度 解压---->Python --->./configure-->yum install -y zlib* ...
- (转)linux下进程的进程最大数、最大线程数、进程打开的文件数和ulimit命令修改硬件资源限制
ulimit命令查看和更改系统限制 ulimit命令详解 ulimit用于shell启动进程所占用的资源,可以用来设置系统的限制 语法格式 ulimit [-acdfHlmnpsStvw] [size ...
- hibernate框架的搭建
1 导入所需的jar包 1 导入hibernate必须的jar包 2 导入驱动包 2 创建数据库,准备表,实体 1 创建hibernate数据库 CREATE DATABASE hibernate; ...
- 2.3 js基础--DOM
一.javascript组成 ECMAScript:核心解释器[为我们提供好了最基本的功能:变量声明.函数.语法.运算]. 兼容性:完全兼容. DoM:文档对象 ...
- js中防止事件传播的方法
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...
- Wp及Windows应用商店程序Logo生成器
在开发wp或windows应用商店程序时,需要制作不同分辨率下的logo,往往不同分辨率下的logo仅仅是图片尺寸或图片的内边距不同,为了快速生成不同分辨率下的图片,减少工作量,于是就自己动手开发了个 ...
- 使用java applet通过签名访问客户端串口
前端时间公司有需求要访问客户端串口读取电子称的数据,通过网上资料,决定使用applet通过电子签名的形式实现. 1.先写applet:这里我是使用RXRTcomm.jar LocalFileApple ...
- myeclipse更改类或者是配置文件不用重启tomcat的方法
一.修改java代码(如action)无需重启与部署方法 方法1:在WebRoot下的META-INF文件夹中新建一个名为context.xml文件,里面添加如下内容(要区分大小写): <Con ...
- 服务器LIUNX之如何解决矿机问题
点进来的基本都是遇到liunx变矿机的小伙伴吧(cpu运载300%) 卡的连终端都很难打开 开下来之后提示 大意是, 到xxx网站给钱了事, 不过基本这个网站基本也上不去, 要么是暴力破解, 要么是通 ...
- java集合框架(二):HashTable
HashTable作为集合框架中的一员,现在是很少使用了,一般都是在面试中会问到其与HashMap的区别.为了能在求职的时候用上场,我们有必要对其原理进行解读. HashTable的实现原理跟Hash ...