Codeforces 729C Road to Cinema(二分)
题目链接 http://codeforces.com/problemset/problem/729/C
题意:n个价格c[i],油量v[i]的汽车,求最便宜的一辆使得能在t时间内到达s,路途中有k个位置在g[i]的加油站,可以免费加满油,且不耗时间。每辆车有两种运行模式可以随时切换:1.每米一分钟两升油;2.每米两分钟一升油。
看到10^5次加上循环两次就想到二分或者线段树或者看错题意了。
这题二分查找一下汽油就可以了,找到最少多少汽油够到达,然后再for一遍找汽油量大的且价格便宜的车即可。
还有一些关系要注意一下的
t(min) = 不符合 (L > v[i])
= L (2 * L <= v[i])
= 3 * L - v[i] (L<=v[i]<2 * L)
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int M = 2e5 + 10;
typedef long long ll;
struct TnT {
int v , f;
}sl[M];
ll pos[M] , sp[M];
bool cmp(TnT a , TnT b) {
return a.f > b.f;
}
int main()
{
int n , k , s , t;
scanf("%d%d%d%d" , &n , &k , &s , &t);
for(int i = 0 ; i < n ; i++) {
scanf("%d%d" , &sl[i].v , &sl[i].f);
}
ll le = 0;
int temp = 0;
for(int i = 0 ; i < k ; i++) {
scanf("%I64d" , &pos[i]);
}
sort(pos , pos + k);
for(int i = 0 ; i < k ; i++) {
sp[temp++] = pos[i] - le;
le = pos[i];
}
if(pos[k - 1] != s) {
sp[temp++] = s - le;
}
sort(sl , sl + n , cmp);
int l = 0 , r = n - 1;
int flag;
while(l <= r) {
int mid = (l + r) >> 1;
ll sum = 0;
flag = 0;
for(int i = 0 ; i < temp ; i++) {
ll gg = sp[i] * 3;
if(sl[mid].f < sp[i]) {
flag = 1;
break;
}
else {
if(2 * sp[i] <= sl[mid].f) {
sum += sp[i];
}
else {
sum += (gg - sl[mid].f);
}
flag = 0;
}
}
if(flag == 1) {
r = mid - 1;
continue;
}
if(sum > t) {
r = mid - 1;
}
else {
l = mid + 1;
}
}
if(l - 1 == -1) {
printf("-1\n");
}
else {
int MIN = sl[l - 1].v;
int cmper = sl[l - 1].f;
for(int i = 0 ; i < n ; i++) {
if(sl[i].f >= cmper) {
MIN = min(MIN , sl[i].v);
}
}
printf("%d\n" , MIN);
}
return 0;
}
Codeforces 729C Road to Cinema(二分)的更多相关文章
- Codeforces #380 div2 C(729C) Road to Cinema
C. Road to Cinema time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- 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 738C Road to Cinema
二分答案. 油量越多,显然通过的时间越少.可以二分找到最小的油量,可以在$t$时间内到达电影院. 一个油箱容量为$v$的车通过长度为$L$的路程需要的最小时间为$max(L,3*L-v)$.计算过程如 ...
- Road to Cinema
Road to Cinema time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【26.83%】【Codeforces Round #380C】Road to Cinema
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- Road to Cinema(贪心+二分)
https://www.cnblogs.com/flipped/p/6083973.html 原博客转载 http://codeforces.com/group/1EzrFFyOc0/co ...
- CodeForces 377B---Preparing for the Contest(二分+贪心)
C - Preparing for the Contest Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d ...
随机推荐
- Selenium+java - 下拉框处理
常见下拉框也分两种:一种是标准控件和非标准控件(一般为前端开发人员自己封装的下拉框),本篇文章中将重点讲解标准下拉框操作. 1.Select提供了三种选择某一项的方法 select.selectByI ...
- 9-1、大型项目的接口自动化实践记录----数据库结果、JSON对比
上一篇写了如何从DB获取预期.实际结果,这一篇分别对不同情况说下怎么进行对比. PS:这部分在JSON对比中也适用. 1.结果只有一张表,只有一条数据 数据格式:因为返回的是dicts_list的格式 ...
- Apache ActiveMQ任意文件写入漏洞(CVE-2016-3088)复现
Apache ActiveMQ任意文件写入漏洞(CVE-2016-3088)复现 一.漏洞描述 该漏洞出现在fileserver应用中,漏洞原理:ActiveMQ中的fileserver服务允许用户通 ...
- 用CSS来定义<p>标签,要求实现以下效果:字体颜色再IE6下为黑色,IE7下为红色,IE8下为绿色,其他浏览器下为黄色。
<!DOCTYPE html><html><head><meta charset="utf-8"><meta name=&qu ...
- idea使用大全(加载mysql驱动)
1.载入mysql驱动 找到项目结构(project structure) 选Modules 找到右边的加号选择第一个 OK
- 3、K-近邻算法
K最近邻(k-Nearest Neighbor,KNN)分类算法 1.定义:如果一个样本在特征空间中的k个最近似(即特征空间中最临近)的样本中大多数属于某一类别,则该样本也属于这个类别. 2.计算公式 ...
- NS3中一些难以理解的常数
摘要:在NS3的学习中,PHY MAC中总有一些常数,需要理解才能修改.如帧间间隔等.那么,本文做个简单分析,帮助大家理解.针对802.11标准中MAC协议. void WifiMac::Conf ...
- 内存泄漏排查之:Show me your Memory
java 语言有个神奇的地方,那就是你时不时会去关注下内存.(当然了,任何牛逼的同学都应该关注内存) 今天我们就来这么场景吧:某应用运行了一段时间后,ecs监控报警了,内存比较高了,怎么办?随着时间的 ...
- 完整原型链详细图解之JS构造函数、原型 原型链、实例化对象
一.首先说一下什么是构造函数: 构造函数:用来在创建对象时初始化对象.特点:构造函数名一般为大写字母开头:与new运算符一起使用来实例化对象. 举例: function Person(){} //Pe ...
- 7.15 迭代器 for循环的本质 生成器
迭代器 迭代:更新换代的过程,每次的迭代都必须基于上一次的结果 迭代器:迭代取值的工具 作用 迭代器提供了一种不依赖于索引取值的方式 根据以上对于迭代的描述,如果只是简单的重复,不算迭代,如下: n ...