https://www.cnblogs.com/flipped/p/6083973.html       原博客转载

http://codeforces.com/group/1EzrFFyOc0/contest/738/problem/C     题目链接

题意:n个价格c[i],油量v[i]的汽车,求最便宜的一辆使得能在t时间内到达s,路途中有k个位置在g[i]的加油站,可以免费加满油,且不耗时间。每辆车有两种运行模式可以随时切换:1.每米一分钟两升油;2.每米两分钟一升油。

题解:二分求可以到达s的最小油量。对于油量v,能到达s的条件是:油量足够经过最长路程(中途不能加油);总的最小时间不超过t。为了求最小时间,可以用线性规划:一段不加油的路程长度为l,假设x米运行的是1.模式,则l-x米运行的是2.模式。总时间为t。则有

  t=x+2∗(l−x)

  v≥x∗2+l−x

  x≥0l−x≥0(1)

 {   t=x+2∗(l−x)

  v≥x∗2+l−x

  x≥0

  l−x≥0

化简一下:

  t=2∗l−x

  x≤v−l

  l≥x≥0(2)

  {t=2∗l−x

  x≤v−l

  l≥x≥0

最后得到:

  tmin=2∗l−xmax
  =2∗l−min(v−l,l)
  =max(l∗3−v,l)tmin
  =2∗l−xmax
  =2∗l−min(v−l,l)
  =max( l∗3−v,l )

且v≥l,可以改为v≥max(l)。

 #include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<set>
#include<vector>
#include<stack>
#include<queue>
#include<map>
using namespace std;
#define ll long long
#define se second
#define fi first
const int Mos = 0x7FFFFFFF; //
const int nMos = 0x80000000; //-2147483648
const int N=2e5+; int n,k,s,t,dis;
int c[N],v[N],g[N]; bool check(int vv) //油量
{
if(vv<dis) return ; //如果开低速的油都不够
int sumt=;
for(int i=;i<=k+;i++)
{
sumt+= max(g[i],*g[i]-vv);
if(sumt>t) return ; //超出时间
}
return ;
}
int main()
{
cin>>n>>k>>s>>t;
for(int i=;i<=n;i++) scanf("%d%d",&c[i],&v[i]);
for(int i=;i<=k;i++) scanf("%d",&g[i]);
g[k+]=s;
sort(g+,g++k);
for(int i=k+;i>=;i--)
dis=max(dis,g[i]-=g[i-]); //找出加油站间最长间隔,顺便把g[i]变为距离前面一个的距离
int l=,r=1e9+,mid,res=;
while(l<=r) //二分找出最少需要的油量;
{
mid=(l+r)>>;
if( check(mid) ) r=mid-,res=mid; //记录最优的res
else l=mid+;
}
int ans=1e9+;
if(res)
for(int i=;i<=n;i++)
if(v[i]>=res) ans=min(ans,c[i]);
if(ans>=1e9+) ans=-; cout<<ans<<endl;
}

Road to Cinema(贪心+二分)的更多相关文章

  1. Codeforces 729C Road to Cinema(二分)

    题目链接 http://codeforces.com/problemset/problem/729/C 题意:n个价格c[i],油量v[i]的汽车,求最便宜的一辆使得能在t时间内到达s,路途中有k个位 ...

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

  5. Road to Cinema

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

  6. poj 2782 Bin Packing (贪心+二分)

    F - 贪心+ 二分 Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu   Description ...

  7. Card Game Cheater(贪心+二分匹配)

    Card Game Cheater Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

  8. The 14th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple - F 贪心+二分

    Heap Partition Time Limit: 2 Seconds      Memory Limit: 65536 KB      Special Judge A sequence S = { ...

  9. 贪心/二分查找 BestCoder Round #43 1002 pog loves szh II

    题目传送门 /* 贪心/二分查找:首先对ai%=p,然后sort,这样的话就有序能使用二分查找.贪心的思想是每次找到一个aj使得和为p-1(如果有的话) 当然有可能两个数和超过p,那么an的值最优,每 ...

  10. Codeforces Round #768 (Div. 2) D. Range and Partition // 思维 + 贪心 + 二分查找

    The link to problem:Problem - D - Codeforces   D. Range and Partition  time limit per test: 2 second ...

随机推荐

  1. Docker 容器的资源限制 cgroup(九)

    目录 一.cgroup简介 二.CPU资源配额控制 1.CPU份额控制 2.CPU周期控制 3.CPU core控制 4.CPU配额控制参数的混合使用 二.对内存的限额 三.对 Block IO 的限 ...

  2. 【数据库开发】is not allowed to connect to this MySQL server解决办法

    ERROR 1130: Host '192.168.1.3′ is not allowed to connect to this MySQL server这是告诉你没有权限连接指定IP的主机,下面我们 ...

  3. CenOS 7 安装Tomcat

    1.首先需要安装jdk yum install java-1.8.0-openjdk-devel.x86_64 2.下载 http://mirrors.tuna.tsinghua.edu.cn/apa ...

  4. 48.javascript基础学习

    javascript基础学习:   http://www.w3school.com.cn/jsref/index.asp jS的引入方式: 1.行间事件:为某一个具体的元素标签赋予js内容,oncli ...

  5. 安卓中listview中性能优化的处理

    1.在adapter中的getView方法中尽量少使用逻辑 不要在你的getView()中写过多的逻辑代码,我们能够将这些代码放在别的地方.比如: 优化前的getView(): @Override p ...

  6. 通过js操作,将div设置为contenteditable的内容设为全选状态

    因为div设置为contenteitable可编辑的文本内容用 select()选择全部内容不生效,所以只能用下列方法: 先 creatTextRange或者 createRange <div ...

  7. java用POI导出Excel

    架构SSM + Maven 一.添加依赖: <dependency> <groupId>org.apache.poi</groupId> <artifactI ...

  8. 本地Pycharm将spark程序发送到远端spark集群进行处理

    前言 最近在搞hadoop+spark+python,所以就搭建了一个本地的hadoop环境,基础环境搭建地址hadoop2.7.7 分布式集群安装与配置,spark集群安装并集成到hadoop集群, ...

  9. hdu 4333 扩展kmp+kmp重复字串去重

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4333 关于kmp next数组求最短重复字串问题请看:http://www.cnblogs.com/z ...

  10. (四)Activiti之流程定义部署之ZIP方式和流程定义查询

    一.流程定义部署之ZIP方式 上一章节我们使用classpath的方式加载流程定义文件,这里我们使用ZIP的方式. 1.1 用activiti插件生成bpmn和png图片之后,压缩到一个zip格式的压 ...