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 ...
随机推荐
- 【iOS】Receiver type 'XXX' for instance message is a forward declaration
今天遇到这个错误.刚开始字体太大,没显示全,后来调小字体之后看到了完整提示信息: 之后就忽然想起没引入相关的类,添加 #import "RDVTabBarItem.h" 就行了.
- 一个项目中:只能存在一个 WebMvcConfigurationSupport (静态文件失效之坑)
一个项目中:只能存在一个 WebMvcConfigurationSupport 在一个项目中WebMvcConfigurationSupport只能存在一个,多个的时候,只有一个会生效. 静态文件访问 ...
- 为什么阿里Java规约禁止使用Java内置线程池?
IDEA导入阿里规约插件,当你这样写代码时,插件就会自动监测出来,并给你红线提醒. 告诉你手动创建线程池,效果会更好. 在探秘原因之前我们要先了解一下线程池 ThreadPoolExecutor 都有 ...
- Zabbix-agentd错误整理
一.无法启动 (一).当时环境 Firewalld与Selinux,Iptables都为关闭 配置环境 OS:CentOS Zabbix-server IP:10.18.43.71 Hostname: ...
- Kafka学习(四)-------- Kafka核心之Producer
通过https://www.cnblogs.com/tree1123/p/11243668.html 已经对consumer有了一定的了解.producer比consumer要简单一些. 一.旧版本p ...
- sqoop增量导数据
sqoop要实现增量导入参数到hive或者hdfs 1.需要在mysql中创建可以自动更新的字段,当插入数据时和更新数据时改字段自动更新,如图中update_time,当数据插入时会记录更新为插入时间 ...
- kubernetes lowB安装方式
kubernetes离线安装包,仅需三步 基础环境 关闭防火墙 selinux $ systemctl stop firewalld && systemctl disable fire ...
- 第三章 Linux基本命令操作
第三章 Linux基本命令操作 ¨ 本节所讲内容: ¨ 3.1 Linux终端介绍 Shell提示符 Bash Shell基本语法 ¨ 3.2 基本命令的使用:ls.pwd.cd.hist ...
- javascript 异步请求封装成同步请求
此方法是异步请求封装成同步请求,加上token验证,环境试用微信小程序,可以修改文件中的ajax,进行封装自己的,比如用axios等 成功码采用标准的 200 到 300 和304 ,需要可以自行修改 ...
- 素数筛法(Eratosthenes筛法)
介绍 Eratosthenes筛法,又名埃氏筛法,对于求1~n区间内的素数,时间复杂度为n log n,对于10^6^ 以内的数比较合适,再超出此范围的就不建议用该方法了. 筛法的思想特别简单: 对于 ...