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. excel自学笔记 from av50264533

    1.函数公式 MINUTE(serial_number)  函数解读 Serial_number 表示一个时间值,其中包含要查找的分钟  函数公式 NOW()  函数解读 显示出现在的时间 计算通话时 ...

  2. 【miscellaneous】【ARM-Linux开发】ARM平台基于嵌入式Linux Gstreamer 使用

    1). 简介 随着ARM平台性能的日益强大和嵌入式设备的发展,对于多媒体处理如音视频播放,摄像头,流媒体处理等需求也日益增多,本文就通过几个基于嵌入式Linux下多媒体应用的示例来简单展示下使用Gst ...

  3. hupu面试

    1.mybatis更新一条数据时,如果某字段为空,则不更新它,使用默认值? <update id="updateProduct" parameterType="Pr ...

  4. iostat (转https://www.cnblogs.com/ftl1012/p/iostat.html)

    iostat是I/O statistics(输入/输出统计)的缩写,iostat工具将对系统的磁盘操作活动进行监视.它的特点是汇报磁盘活动统计情况,同时也会汇报出CPU使用情况.iostat也有一个弱 ...

  5. CDH建表字符集问题

    登陆metadata数据库: show variables like 'character_set%'; alter database hivemeta default character set l ...

  6. oracle学习笔记day1

    oracle数据库前言 oracle sqllesson1 Selecting Rowslesson2 Sorting & Limiting Selected Rowslesson3 Sing ...

  7. AtCoder整理(持续更新中……)

    做了那么久的atcoder觉得自己的题解发的很乱 给有想和我一起交流atcoder题目(或者指出我做法的很菜)(或者指责我为什么整场比赛只会抄题解)的同学一个索引的机会??? 于是写了个爬虫爬了下 A ...

  8. 第一个vue程序:hello,vlue

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http ...

  9. Maven项目上总有一个小红叉问题

    一.maven project facet dynamic web module错误解决方案 在Eclipse中使用maven创建web-app的过程中总会遇到一个问题,cannot change v ...

  10. Go学习路径--相关基础

    现在开始接触Go一段时间了,基本路径就是看基础学习材料,开始写项目,有问题找解决问题的方法.这里记录一下学习过程. go相关文章 Golang适合高并发场景的原因分析 go build 不同系统下的可 ...