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. MATLAB分类与预测算法函数

    1.glmfit() 功能:构建一个广义线性回归模型. 使用格式:b=glmfit(X,y,distr),根据属性数据X以及每个记录对应的类别数据y构建一个线性回归模型,distr可取值为:binom ...

  2. Win10下 jdk的安装

    jdk 的下载地址 https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html 在 D 盘 ...

  3. [转帖]彻底弄懂UTF-8、Unicode、宽字符、locale

    彻底弄懂UTF-8.Unicode.宽字符.locale linux后端开发   已关注   彻底弄懂UTF-.Unicode.宽字符.locale unicode 是字符集 utf-8是编码格式.. ...

  4. Linux安装 PostgreSQL

    1.在线安装 yum install postgresql-server -y 2.初始化数据库 service postgresql initdb 3.设置自动启动 hkconfig postgre ...

  5. Paypal、Stripe、Braintree,跨境电商金流第三方支付该用哪家?

    在台湾做跨境电子商务生意,电商网站的金流肯定是一个最大的麻烦,Paypal或是Stripe和Braintree则是国际上大家最常用的金流整合第三方支付服务商.这些金流服务大幅简化网站付费过程,都让消费 ...

  6. 【C++札记】new和delete

    介绍 1.malloc,free和new,delete区别. a.malloc,free是C/C++的标准库函数.new,delete是c++的操作符. b.malloc申请的是内存,严格意义不是&q ...

  7. Excel时间序列函数

    year 返回对应于某个日期的年份. month 返回对应于某个日期的月份. day 返回对应于某个日期的年份. weekday 返回对应于某个日期的天数. weeknum 返回对应日期在本年中是第几 ...

  8. Oracle数据库——查询所有用户

    查询数据库所有用户(ALL_USERS)的用户名,用户编号,创建日期 默认应该有36个用户 SELECT * FROM ALL_USERS; 查看ALL_USERS的结构 DESC ALL_USERS ...

  9. ActiveMQ Queue示例

    一.Queue 发送 public class JmsSend { public static void main(String[] args) throws JMSException { Conne ...

  10. (八)CXF之用spring添加拦截器

    一.案例 本章案例是基于CXF之自定义拦截器基础之上改造的,目的是在服务端中用spring添加拦截器 配置web.xml <?xml version="1.0" encodi ...