题目链接 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(二分)的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 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 ...

  4. CodeForces 738C Road to Cinema

    二分答案. 油量越多,显然通过的时间越少.可以二分找到最小的油量,可以在$t$时间内到达电影院. 一个油箱容量为$v$的车通过长度为$L$的路程需要的最小时间为$max(L,3*L-v)$.计算过程如 ...

  5. Road to Cinema

    Road to Cinema time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  6. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  7. 【26.83%】【Codeforces Round #380C】Road to Cinema

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  8. Road to Cinema(贪心+二分)

    https://www.cnblogs.com/flipped/p/6083973.html       原博客转载 http://codeforces.com/group/1EzrFFyOc0/co ...

  9. CodeForces 377B---Preparing for the Contest(二分+贪心)

    C - Preparing for the Contest Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d ...

随机推荐

  1. Python基础总结之第十一天开始【再深入一下函数,重新认识一下】(新手可相互督促)

    感谢最近大家的关注,希望我的学习笔记对大家有帮助!也感谢各位的评论和推荐,请多多指教. 在重新认识函数之前,我们先看两个函数.一个是我们在前面笔记经常用到的print()  :另一个是input() ...

  2. luogu1373_小a和uim之大逃离 多维dp

    传送门 巧妙之处在于dp的设计只用设计差值即可,因此不会mle,枚举的顺序问题也解决了 #include <bits/stdc++.h> using namespace std; #def ...

  3. [ubuntu][deepin]系统增加自定义开机启动项

    [ubuntu][deepin]系统增加自定义开机启动项 进行配置 cd /etc/init.d/ ls vim myScript nginx实例 #! /bin/sh # chkconfig: # ...

  4. Apache 80端口可以访问,8080却不可访问

    RT, 记录一下,后面看是否有解决方案.

  5. Netty学习(七)-Netty编解码技术以及ProtoBuf和Thrift的介绍

    在前几节我们学习过处理粘包和拆包的问题,用到了Netty提供的几个解码器对不同情况的问题进行处理.功能很是强大.我们有没有去想这么强大的功能是如何实现的呢?背后又用到了什么技术?这一节我们就来处理这个 ...

  6. manifest.json 解析--手机web app开发笔记(三-2)

    四.SDK配置和模块权限配置 SDK 就是 Software Development Kit 的缩写,中文意思就是“软件开发工具包”,也就是辅助开发某一类软件的相关文档.范例和工具的集合都可以叫做“S ...

  7. 记一次上线部分docker不打日志的问题排查

    一次正常的上线,发了几台docker后,却发现有的机器打了info.log里面有日志,有的没有.排查问题开始: 第一:确认这台docker是否有流量进来,确认有流量进来. 第二:确认这台docker磁 ...

  8. 安全测试基础2-sqlmap演练

    sqlmap简介 sqlmap是一个开源的渗透测试工具,可以用来进行自动化检测,利用SQL注入漏洞,获取数据库服务器的权限. 它具有功能强大的检测引擎,针对各种不同类型数据库的渗透测试的功能选项,包括 ...

  9. 【hdu 2544最短路】【Dijkstra算法模板题】

    Dijkstra算法 分析 Dijkstra算法适用于边权为正的情况.它可用于计算正权图上的单源最短路( Single-Source Shortest Paths, SSSP) , 即从单个源点出发, ...

  10. OpenResty 社区王院生:APISIX 的高性能实践

    2019 年 7 月 6 日,OpenResty 社区联合又拍云,举办 OpenResty × Open Talk 全国巡回沙龙·上海站,OpenResty 软件基金会联合创始人王院生在活动上做了&l ...