Technocup 2017 - Elimination Round 2 C. Road to Cinema —— 二分
题目链接:http://codeforces.com/problemset/problem/729/C
1 second
256 megabytes
standard input
standard output
Vasya is currently at a car rental service, and he wants to reach cinema. The film he has bought a ticket for starts in t minutes.
There is a straight road of length s from the service to the cinema. Let's introduce a coordinate system so that the car rental service
is at the point 0, and the cinema is at the point s.
There are k gas stations along the road, and at each of them you can fill a car with any amount of fuel for free! Consider that this
operation doesn't take any time, i.e. is carried out instantly.
There are n cars in the rental service, i-th
of them is characterized with two integers ci and vi —
the price of this car rent and the capacity of its fuel tank in liters. It's not allowed to fuel a car with more fuel than its tank capacity vi.
All cars are completely fueled at the car rental service.
Each of the cars can be driven in one of two speed modes: normal or accelerated. In the normal mode a car covers 1 kilometer in 2minutes,
and consumes 1 liter of fuel. In the accelerated mode a car covers 1 kilometer
in 1 minutes, but consumes 2 liters
of fuel. The driving mode can be changed at any moment and any number of times.
Your task is to choose a car with minimum price such that Vasya can reach the cinema before the show starts, i.e. not later than in tminutes.
Assume that all cars are completely fueled initially.
The first line contains four positive integers n, k, s and t (1 ≤ n ≤ 2·105, 1 ≤ k ≤ 2·105, 2 ≤ s ≤ 109, 1 ≤ t ≤ 2·109) —
the number of cars at the car rental service, the number of gas stations along the road, the length of the road and the time in which the film starts.
Each of the next n lines contains two positive integers ci and vi (1 ≤ ci, vi ≤ 109) —
the price of the i-th car and its fuel tank capacity.
The next line contains k distinct integers g1, g2, ..., gk (1 ≤ gi ≤ s - 1) —
the positions of the gas stations on the road in arbitrary order.
Print the minimum rent price of an appropriate car, i.e. such car that Vasya will be able to reach the cinema before the film starts (not later than in t minutes).
If there is no appropriate car, print -1.
3 1 8 10
10 8
5 7
11 9
3
10
2 2 10 18
10 4
20 6
5 3
20
In the first sample, Vasya can reach the cinema in time using the first or the third cars, but it would be cheaper to choose the first one. Its price is equal to 10, and the capacity of its fuel tank is 8. Then Vasya can drive to the first gas station in the accelerated mode in 3minutes, spending 6 liters of fuel. After that he can full the tank and cover 2 kilometers in the normal mode in 4 minutes, spending 2liters of fuel. Finally, he drives in the accelerated mode covering the remaining 3 kilometers in 3 minutes and spending 6 liters of fuel.
题解:
1.由于题目没说明车越贵,容量越大,所以需要将价格贵但容量小的车丢弃。
做法是:先按车的容量升序排列,然后用单调队列处理,使得队列中的车的价格也递增。
2.二分车的下标。
单调队列:
int N = ;
for(int i = ; i<=n; i++)
{
while(N>= && a[i]<=a[N]) N--; // a[i]<a[N] 还是 a[i]<=a[N]视情况而定。
a[++N] = a[i];
}
代码如下:
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const double eps = 1e-;
const int INF = 2e9;
const LL LNF = 9e18;
const int mod = 1e9+;
const int maxn = 2e5+; LL n,k,s,t, g[maxn];
LL N; struct node
{
LL c,v;
bool operator<(const node&x)const{
return v<x.v;
}
}a[maxn]; void init()
{
cin>>n>>k>>s>>t;
for(int i = ; i<=n; i++)
scanf("%lld%lld",&a[i].c, &a[i].v);
for(int i = ; i<=k; i++)
scanf("%lld",&g[i]); g[++k] = s; //将终点也放进去
sort(g+,g++k); N = ;
sort(a+,a++n); //按车的汽油容量升序排序
for(int j = ; j<=n; j++) //单调队列
{
while(N>= && a[j].c<=a[N].c) N--;
a[++N] = a[j];
}
} int test(int pos)
{
LL x, y, T = ; //x为以快速行驶的路程, y为以常速行驶的路程
LL capa = a[pos].v;
for(int i = ; i<=k; i++)
{
LL dis = g[i]-g[i-]; if(capa<dis) //以常速都跑不完
return ;
else if(capa<*dis ) //快速+常速 or 常速
x = capa - dis, y = capa - *x;
else //可以全程以快速行驶
x = dis, y = ; T += x + *y; //更新时间
if(T>t) return ; //超时
}
return ;
} void solve()
{
LL l = , r = N;
while(l<=r)
{
LL mid = (l+r)>>;
if(test(mid))
r = mid - ;
else
l = mid + ;
}
printf("%lld\n",l==N+? - : a[l].c);
} int main()
{
init();
solve();
}
Technocup 2017 - Elimination Round 2 C. Road to Cinema —— 二分的更多相关文章
- Codeforces Round #380 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 2)C. Road to Cinema 二分
C. Road to Cinema time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- codeforces Codeforces Round #380 (Div. 1, Rated, Based on Technocup 2017 - Elimination Round 2)// 二分的题目硬生生想出来ON的算法
A. Road to Cinema 很明显满足二分性质的题目. 题意:某人在起点处,到终点的距离为s. 汽车租赁公司提供n中车型,每种车型有属性ci(租车费用),vi(油箱容量). 车子有两种前进方式 ...
- Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) C
Description Santa Claus has Robot which lives on the infinite grid and can move along its lines. He ...
- Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) B
Description Santa Claus decided to disassemble his keyboard to clean it. After he returned all the k ...
- Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) A
Description Santa Claus is the first who came to the Christmas Olympiad, and he is going to be the f ...
- Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) D. Santa Claus and a Palindrome STL
D. Santa Claus and a Palindrome time limit per test 2 seconds memory limit per test 256 megabytes in ...
- Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) E. Santa Claus and Tangerines
E. Santa Claus and Tangerines time limit per test 2 seconds memory limit per test 256 megabytes inpu ...
- Codeforces Round #380 (Div. 1, Rated, Based on Technocup 2017 - Elimination Round 2)
http://codeforces.com/contest/737 A: 题目大意: 有n辆车,每辆车有一个价钱ci和油箱容量vi.在x轴上,起点为0,终点为s,中途有k个加油站,坐标分别是pi,到每 ...
- Codeforces Round #380 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 2) E. Subordinates 贪心
E. Subordinates time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...
随机推荐
- 洛谷——P1825 [USACO11OPEN]玉米田迷宫Corn Maze
P1825 [USACO11OPEN]玉米田迷宫Corn Maze 题目描述 This past fall, Farmer John took the cows to visit a corn maz ...
- win7快捷键和ubuntu快捷键
http://www.cnblogs.com/xfiver/archive/2010/12/08/1899905.html http://www.pc841.com/article/20121203- ...
- Codeforces Round #321 (Div. 2) Kefa and Park 深搜
原题链接: 题意: 给你一棵有根树,某些节点的权值是1,其他的是0,问你从根到叶子节点的权值和不超过m的路径有多少条. 题解: 直接dfs一下就好了. 代码: #include<iostream ...
- CDOJ_149 解救小Q
原题网址:http://acm.uestc.edu.cn/#/problem/show/149 小Q被邪恶的大魔王困在了迷宫里,love8909决定去解救她. 迷宫里面有一些陷阱,一旦走到陷阱里,就会 ...
- Failed to check the status of the service报错解决
报这个错误是因为我的application_context.service.xml 文件里的的dubbo声明暴露口时的ref属性写错了. <dubbo:service interface=&qu ...
- 1.搭建maven,eclipse创建maven项目
1.下载maven包,下载地址为:http://maven.apache.org/download.cgi 2.解压zip包 3.eclipse 引入maven: window-Preferences ...
- 安装Vmware增强工具
主机: Win7 虚拟机: VMware8.0+Debian6 目标: 离线安装软件包和VMware Tools 在虚拟机上安装完debian6后 1.在vmware的菜单中选择Vm->inst ...
- win10 sublime license
—– BEGIN LICENSE —– TwitterInc 200 User License EA7E-890007 1D77F72E 390CDD93 4DCBA022 FAF60790 61AA ...
- 关于Gradle配置的小结
前言 使用 Android Studio 来开发 Android 工程的过程中,接触 Gradle 是不可避免的,比如配置签名.引入依赖等.那么 Gradle 到底是什么东西呢? Gradle 是一个 ...
- mysql 查询表索引的命令详解
http://hi.baidu.com/wylinux/item/cbc458c2984381300831c651查看索引命令mysql> show index from tblname;mys ...