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) 有三种运动方式: ...
随机推荐
- 设计模式学习总结(十)责任链模式(Chain Of Responsibility)
责任链主要指通过一连串的操作来实现某项功能或者在处理相关的业务时,对于自己的业务则进行处理,反之,对于不属于自己的业务,则进行下发! 一.示例展示: 以下例子主要通过对煤矿对井下警告信息的处理来进 ...
- GreenPlum 大数据平台--运维(一)
.最后分析或真空或创建表或等... Select * from pg_stat_operations where schemaname='SCHEMA NAME ' and actionname in ...
- ASP.NET复习笔记(1)
今天是个好日子,伴着早上八点的朝阳,我背上书包,提上电脑,带上一根网线,风风火火的冲向教室,因为,我终于想好博客内容写啥了——这不是快期末了么,我就写复习,虽然有些课程还没讲完,但并不影响我做复习,正 ...
- ArrayList集合长度的问题
// 每次集合中实际包含的元素个数(count)超过了可包含元素的个数capcity //的时候集合就会向内存中申请多开启一倍的空间,来保证集合长度够用 static void Main(strin ...
- 01.使用File类读写文件
使用File类去读数据: 方法一:使用ReadAllBytes(); 方法 namespace _01.使用File类读写数据01 { class Program { static void Main ...
- 移除script标签引起的兼容性问题
一.应用场景: 有时候我们需要动态创建script标签实现脚本的按需加载,我们会为script标签绑定onload或者onreadystatechange事件,用于检测动态脚本是否加载并执行完毕,在事 ...
- Java集合篇三:Vector
package com.test.collection; import java.util.Vector; public class MyVector { /** * @param args */ p ...
- js添加、修改、删除xml节点例子
version="1.0" encoding="gb2312"?> . <bookstore> . <book genre=" ...
- em和px
在国内网站中,包括三大门户,以及“引领”中国网站设计潮流的蓝色理想,ChinaUI等都是使用了px作为字体单位.只有百度好歹做了个可调的表率.而 在大洋彼岸,几乎所有的主流站点都使用em作为字体单位, ...
- SharePoint 2013 - Upgrade
1. 升级到SP2013时,需要对data connection文件(UDCX文件)进行修改: 1. Mark all UDCX File (Ctrl + A) and open them. 2. F ...