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实现文件压缩与解压
Java实现ZIP的解压与压缩功能基本都是使用了Java的多肽和递归技术,可以对单个文件和任意级联文件夹进行压缩和解压,对于一些初学者来说是个很不错的实例.(转载自http://www.puiedu. ...
- css:去掉手机浏览器上点击时的边框和阴影
outline:none;(去掉蓝框) -webkit-tap-highlight-color:rgba(0,0,0,0) ;(去掉阴影)适用于ios,Android
- IIS内存溢出-设置IIS的应用程序池
在ASP.NET Web服务器上,ASP.NET所能够用到的内存,通常不会等同于所有的内存数量.在machine.config(C:/WINDOWS/Microsoft.NET/Framework/v ...
- java 的面向对象
1.java是什么语言: java也属于面向对象编程语言. 2.面向对象的三大特性: 封装 ,继承, 多态. 3.什么是对象: 对象是真实存在的唯一失误. 面向对象的英文是(oop),面向对象的编程思 ...
- Eclipse各种配置
1.配置工作空间编码 Window -- Preferences-- Genereal -- Workspace (Text file encoding -- orther -- utf-8) 2 ...
- android studio中断开SVN连接,并彻底清理项目中的.svn文件
首先,断开SVN连接: 在使用SVN过程中,我们会发现当我们第一次share到subversion的时候,下次就无法重新share了,也无法断开连接,就算我们将工程目录下的.svn目录删除它还是会无法 ...
- 反射,System.Type类
http://m.blog.csdn.net/blog/woddle/40623333 两个现实中的例子:1.B超:大家体检的时候大概都做过B超吧,B超可以透过肚皮探测到你内脏的生理情况.这是如何做到 ...
- Windows XP SP3下成功编译CUint2.1-3
软件环境:Visual C++ 6.0 操作系统:Windows XP SP3 从sourceforge.net下载CUint-2.1-3.tar.bz解压出目录CUnit-2.1-3 从CUint打 ...
- IIS上虚拟目录下站点的web.config与根站点的web.config冲突解决方法
IIS7.5上在站点下部署虚拟目录,访问虚拟目录下的项目提示与父节点配置冲突.,节点与的<system.web>节点与主站点的<system.web>冲突解决方法: 在站点下的 ...
- Xcode Custom Shortcut
edit file "/Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Resources" add < ...