Codeforces #380 div2 C(729C) Road to Cinema
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 point0, 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 2 liters of fuel. Finally, he drives in the accelerated mode covering the remaining 3 kilometers in 3 minutes and spending 6 liters of fuel.
题目大意:一个一维的路,从距离为0到距离为s,中间有一些加油站,每次都能不耗时加满油,每辆车有c和v,分别表示租金和油量,有两种速度,一公里花1个单位时间消耗2个单位的油,一公里花2个单位的时间花1个单位的油,要求在t秒内到达终点所能租的最便宜的车花多少钱?
做法:稍微思考就能看出是二分,由于每次路过加油站都能加满油而且不耗时,所以争取在能到达下一个加油站(或终点)的前提条件下能开多快开多快,所以如果△s>v,那么v太小了不行,如果△s小于0.5v,那么耗时△t=s,其他情况,计算得△t=3s-v,将每一个△t加起来,判断是否小于等于t。
因此对每一个v都可判断t秒内能不能走到终点,对t取值进行二分,找到满足条件的最小的v,用这个v遍历汽车油量与租金,在满足油量>v的基础上找最小租金。
PS:除了几处手残写错之外,注意加油站的位置不是按顺序给的,所以要排个序。。。本来觉得这道题肯定能做出来,最后剩下2分钟过的,好险。
代码:
#include <cstdio>
#include <ctime>
#include <cstdlib>
#include <iostream>
#include <cstring>
#include <cmath>
#include <queue>
#include <algorithm>
#define N 200005
#define inf 1e18+5
typedef long long ll;
#define rep(i,n) for(i=0;i<n;i++)
using namespace std;
ll k,m,n,t,cc,s,ma,mi;
ll g[N];
struct st{
ll c;
ll v;
}a[N];
bool check(ll v);
int main()
{
while(scanf("%lld%lld%lld%lld",&n,&k,&s,&t)!=EOF){
ma=-;
mi=inf;
for(int i=;i<=n;i++){
scanf("%lld %lld",&a[i].c,&a[i].v);
ma=max(ma,a[i].v);
mi=min(mi,a[i].v);
}
for(int i=;i<=k;i++){
scanf("%lld",&g[i]);
}
sort(g+,g+k+);
ll l=mi,r=ma;
while(l<r-){
ll mid=(l+r)>>;
if(check(mid)==){
r=mid;
}
else {
l=mid;
}
}
ll ans=;
if(check(l)) ans=l;
else if(check(r)) ans=r;
else ans=inf;
ll aa=inf;
for(int i=;i<=n;i++){
if(a[i].v>=ans){
aa=min(aa,a[i].c);
}
}
if(aa==inf) printf("-1\n");
else printf("%lld\n",aa);
} return ;
}
bool check(ll v){ ll t1=;
ll s1=g[];
if(s1>v) {
return ;
}
else if(s1<=v&&s1>=(v/2.0)){
t1+=*s1-v;
}
else {
t1+=s1;
}
for(int i=;i<k;i++){
ll s1=g[i+]-g[i];
if(s1>v) {
return ;
}
else if(s1<=v&&s1>=(v/2.0)){
t1+=*s1-v;
}
else {
t1+=s1;
}
}
s1=s-g[k];
if(s1>v) {
return ;
}
else if(s1<=v&&s1>=(v/2.0)){
t1+=*s1-v;
}
else {
t1+=s1;
}
if(t1>t) return ;
else return ;
}
Codeforces #380 div2 C(729C) Road to Cinema的更多相关文章
- Codeforces 729C Road to Cinema(二分)
题目链接 http://codeforces.com/problemset/problem/729/C 题意:n个价格c[i],油量v[i]的汽车,求最便宜的一辆使得能在t时间内到达s,路途中有k个位 ...
- Codeforces #380 div2 E(729E) Subordinates
E. Subordinates time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...
- Codeforces #380 div2 D(729D) Sea Battle
D. Sea Battle time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- Codeforces #380 div2 B(729B) Spotlights
B. Spotlights time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- 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 ...
- Technocup 2017 - Elimination Round 2 C. Road to Cinema —— 二分
题目链接:http://codeforces.com/problemset/problem/729/C C. Road to Cinema time limit per test 1 second m ...
- Codeforces #180 div2 C Parity Game
// Codeforces #180 div2 C Parity Game // // 这个问题的意思被摄物体没有解释 // // 这个主题是如此的狠一点(对我来说,),不多说了这 // // 解决问 ...
- Road to Cinema
Road to Cinema time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- Codeforces #541 (Div2) - E. String Multiplication(动态规划)
Problem Codeforces #541 (Div2) - E. String Multiplication Time Limit: 2000 mSec Problem Descriptio ...
随机推荐
- tesseract3.01的训练和使用
相关源码.资源下载:http://code.google.com/p/tesseract-ocr/downloads/list 训练步骤: 1. Generate Training Images:生 ...
- Integer Break
Given a positive integer n, break it into the sum of at least two positive integers and maximize the ...
- 数据转移发现font有问题
本地正常 以为是mime.types没有 但是发现是存在的 然后根据提示百度了很久都没有解决 解决: 去字体官网下载改字体文件下来 上传到服务器 发现可以正常访问 说明不是服务器的问题 有个提示 i ...
- 把cmd信息中的正常和异常输出分别输出到不同txt文件中
场景一: 1.大量滚动信息容纳不下,在小黑屏中被冲刷掉. 2.希望把正常输出和异常输出分别输出到不同地方. 相关命令 一共有4个输出到文件的命令,现以jar命令打war包举例说明: 命令 说明 举例 ...
- (转载)持续集成(第二版)[来自:Martin Fowler]
转载自:iTech的博客 持续集成(第二版) 作者:Martin Fowler 译者:雷镇 持续集成 是一种软件开发实践.在持续集成中,团队成员频繁集成他们的工作成果,一般每人每天至少集成一次,也可以 ...
- Java Calendar 注意事项
Java JDK 提供了java.util.Calendar来处理日期和时间.Calendar是一个抽象类,是所有日历的模板,因此我们可以继承Calendar来实现其他的历法(比如阴历). Java提 ...
- Maven 命令速记
1. 创建项目 1) 创建父目录 mvn archetype:generate -DgroupId=com.qunar.training -DartifactId=training -Dversion ...
- PHP使用命名空间:别名/导入(Aliasing/Importing)
1.导入,就是使用use操作符 2.在一个类中导入了另一个类之后,当前的命名空间仍然是当前类的命名空间 3.注意对命名空间中的名称(包含命名空间分隔符的完全限定名称如 Foo\Bar以及相对的不包含命 ...
- windows qt 编译 boost 添加 路径
win32-msvc2015: { contains(QMAKE_HOST.arch, x86):{ INCLUDEPATH += D:\3SDK\boost_1_61_0 LIBS += -LD:\ ...
- 下载Spring框架开发包
1.打开官网: http://spring.io/,打开project >> spring framework 2.在右侧找到要用的版本,如4.3.4,打开reference,搜索&quo ...