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 ...
随机推荐
- ML| EM
What's xxx The EM algorithm is used to find the maximum likelihood parameters of a statistical model ...
- sort、dirname、添加环境变量、修改主机名、别名IP、静态路由
1.split-按照指定行数或大小分割文件 -l:指定行数 -a:指定文件后缀长度 -d:使用数字作为后缀 -b:指定大小 # 以10行为单位对文件进行分割 split -l 10 /etc/init ...
- URAL - 1860 Fiborial
Discription Consider a sequence F i that satisfies the following conditions: Find the number of dif ...
- 在C#的数据类型中,什么属于值类型,什么属于引用类型
转自原文 在C#的数据类型中,什么属于值类型,什么属于引用类型 类型:整数,浮点数,高精度浮点数,布尔,字符,结构,枚举引用类型:对象(Object),字符串,类,接口,委托,数组除了值类型和引用类型 ...
- Android 中的Canvas画图
Android中有一个Canvas类,Canvas类就是表示一块画布,你可以在上面画你想画的东西.当然,你还可以设置画布的属性,如画布的颜色/尺寸等.Canvas提供了如下一些方法: Canvas() ...
- exec: "docker-proxy": executable file not found in $PATH
在执行 docker run 操作的时候,一直报如下错误: [root@etcd1 vagrant]# docker run --name redis-6379 -p 6379:6379 -d --r ...
- 【CSS】使用CSS控制文字过多自动省略号
使用CSS可以设置一下样式: <style> u,small{ overflow: hidden; text-overflow: ellipsis; display: -webkit-bo ...
- Fresco的使用<一>
版权声明:本文为博主原创文章,未经博主允许不得转载. 目录(?)[+] 引入Fresco dependencies { // 添加依赖 compile 'com.facebook.fresco:fre ...
- cug oj 1479 Treasure Chest Lock (区间dp 思维)
1479: Treasure Chest Lock Time Limit: 1 Sec Memory Limit: 128 MB Submit: 7 Solved: 5 [id=1479" ...
- Mybatis分页插件-PageHelper的使用
转载:http://blog.csdn.net/u012728960/article/details/50791343 Mybatis分页插件-PageHelper的使用 怎样配置mybatis这里就 ...