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. [多转合成] 使用pycaffe保存各个层的特征图

    # coding=utf-8 #python2 caffe_visualize.py import numpy as np import matplotlib.pyplot as plt import ...

  2. iCMSv7.0.15后台database.admincp文件仍存在SQL注入漏洞

    闲着无聊,国庆时间没事做,又在Q群看到这种公告,只好下个icms慢慢玩.(PS:医院和学校居然都关网站了) 无奈自己太菜,审不出问题.只好上网百度icms之前的漏洞.然后居然成功在iCMSv7.0.1 ...

  3. Windows 10 下使用 MinGW-w64 编译 OpenCV-4.1.1

    1. 下载安装 CMake 2. 下载安装 MinGW-w64,假设安装于 X:\path\to\MinGW-w64 此处注意选择 POSIX 版本而非 Win32 版本,因为 OpenCV 调用了标 ...

  4. VSCode 查看、还原本地代码历史版本

    参考链接:https://blog.csdn.net/luckystar_99/article/details/100583141

  5. 基于 Spring + Atomikos + Mybatis的多数据源配置(含有BaseDao,BaseService)

    1.spring配置文件 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns=" ...

  6. 离线安装docker,并导入docker镜像

    将docker离线安装包导入到系统中,解压并进入文件夹,使用下述命令进行安装: rpm -ivh *.rpm --nodeps --force 安装完成功使用,docker info 查看docker ...

  7. uwp,c#,全屏播放保持屏幕响应

    在开发视频app的时候,全屏播放一段时间内没有电脑操作,电脑会自动进入睡眠模式,这时就要多写些代码来保持响应了. (这里使用的是MediaElement播放控件,MediaElement需要手动添加代 ...

  8. 解决无/var/log/messages 问题

    转载于:https://blog.csdn.net/C_Major/article/details/51321684 1 内核编程insmod后,Ubuntu查看日志无/var/log/message ...

  9. [转帖]【JVM 知识体系框架总结】

    [JVM 知识体系框架总结] https://www.cnblogs.com/mousycoder/p/11612448.html JVM 内存分布 线程共享数据区:方法区->类信息,静态变量堆 ...

  10. 第三坑:jar包编译版本

    这个是之前往was上发应用的时候踩的一个坑,当时我们知道was的jdk版本是1.6,然后我们是用1.7的jdk,编译版本选的是1.6,然后放上去不对,我们以为是编译的问题,然后又下载了1.6的jdk, ...