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 ...
随机推荐
- 更改XAMPP中MySQL数据库的端口号
更改XAMPP中MySQL数据库的端口号 如果电脑上已安装MySql数据库,还想用XAMPP中自带的数据库就需要更改XAMPP中数据库的端口号,避免和已安装的数据库冲突.本例以更改为3307端口号为例 ...
- C语言中的回调函数(Callback Function)
1 定义和使用场合 回调函数是指 使用者自己定义一个函数,实现这个函数的程序内容,然后把这个函数(入口地址)作为参数传入别人(或系统)的函数中,由别人(或系统)的函数在运行时来调用的函数.函数是你实现 ...
- ASP.Net MVC3安全升级导致程序集从3.0.0.0变为3.0.0.1
开发环境一般引用的是本机 C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET MVC 3\Assemblies下的System.Web.Mvc.dll,当 ...
- iOS常用库之Masonry
简单介绍 Masonry 源码地址:https://github.com/Masonry/Masonry Masonry是一个轻量级的布局框架 拥有自己的描述语法 采用更优雅的链式语法封装自动布局 简 ...
- 升级到macos sierra xcode8 requires additional components to support runing and debugging choose Install to add required components
升级到macos sierra xcode8 报提示:requires additional components to support runing and debugging choose Ins ...
- call
-------siwuxie095 call 调用另一个批处理程序或自身程序段,调用完,程序会回到原来 call 的地方继续执行 如果在脚本或批处理文件外使用 call,则不会在命令行起作用 语法 c ...
- SQL Server 2008 修改表所有者,架构
ALTER SCHEMA 新架构 TRANSFER 旧架构.对象名称
- MM常用表
Table 表描述 MKPF 物料凭证抬头 MSEG 物料凭证段
- js 两数相减
var SecondPrice = document.getElementById("txtSecondPrice"); //秒杀价 var MarketP ...
- NTDLL未文档化函数RtlGetNtVersionNumbers获取操作系统版本
作为新手,对获取操作系统版本号好奇过,因为曾经假象过一个场景:自己的程序在windows xp环境下编译,在windows 2003, windows 7,windows 8是否需要提权或者兼容处理, ...