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 ...
随机推荐
- Java Sha1 加密算法
//下面四个import放在类名前面 包名后面 //import java.io.UnsupportedEncodingException; //import java.security.Messag ...
- Android中的事件传递机制
Android源码版本:API Level 19(Android 4.4) Android事件构成 在Android中,事件主要包括点按.长按.拖拽.滑动等,点按又包括单击和双击,另外还包括单指操作和 ...
- css 下拉列表的制作
圣诞节后上课就是不在状态,一整天都在神游,还感觉特别累,本来想休息休息的,结果某人看不惯我一直吃东西,非得把电脑给我打开,让整理今天所学的内容,想了一下,确实上午讲的用无序列表<ul>做的 ...
- 'Missing recommended icon file - The bundle does not contain an app icon for iPhone / iPod Touch of exactly '120x120' pixels, in .png format'
创建120像素的高分辨率和60个像素定期如上,苹果文档中提到,并设置名称的新图标.例如,icon-120.png和icon-152.png. 将这个图标到你的项目资源文件夹并添加该图标到项目: 在此之 ...
- TopShelf框架创建Windows服务作为Remoting的宿主案例:
1.创建服务 using System; using System.Collections.Generic; using System.Linq; using System.Text; using S ...
- Citrix Reciver提示安装程序集错误
打开注册表查找是否有RegistrySizeLimit这个项目,如果有更改成8个f,如果没有就需要手动建立一个之后输入8个f,操作方法如下: 到了 HKEY_LOCAL_MACHINE\SYSTEM\ ...
- [译]2016年深度学习的主要进展(译自:The Major Advancements in Deep Learning in 2016)
译自:The Major Advancements in Deep Learning in 2016 建议阅读时间:10分钟 https://tryolabs.com/blog/2016/12/06/ ...
- Trie 最长前缀匹配串的实现
http://blog.csdn.net/hguisu/article/details/8131559
- create()创建的控件不能映射消息函数的解决
有时,使用create()在运行时创建的控件不能将消息映射到父窗口内,此时需要使用消息转发的机制,主要原理:注册一个全局的消息,针对接收消息的控件编写继承类,在该继承类中响应消息,并将已注册的全局消息 ...
- vim深入研究
About VIM--Unix及类Unix系统文本编辑器 Vim是一个类似于Vi的著名的功能强大.高度可定制的文本编辑器,在Vi的基础上改进和增加了很多特性.VIM是纯粹的自由软件. Vim普遍被推崇 ...