Read Time

题意:有一个数组,很多指针指在这个数组上,每次每个指针可以向左或向右移动一个位置。给出一些需要访问的位置,问访问用的最少时间。

一个指针只可能转一次方向。二分答案。

 #include<cstdio>
#include<cstring>
#include<algorithm>
#define MAX(a,b) a>b?a:b
using namespace std;
long long ans,hh,tt,mid,a[],b[];
int i,n,m;
bool can(long long x)
{
int i,now,j=;
long long xx,yy; for (i=;i<=n;i++)
{
if (b[j]<a[i])
xx=a[i]-b[j];
else
xx=;
if (xx>x) return ;
yy=MAX((x-xx)/,x-xx*);
while (b[j]<=a[i]+yy&&j<=m)
j++;
if (j>m) return ;
}
if (j<=m) return ;
else
return ;
}
int main()
{
scanf("%d%d",&n,&m);
for (i=;i<=n;i++)
scanf("%I64d",&a[i]);
for (i=;i<=m;i++)
scanf("%I64d",&b[i]);
sort(a+,a++n);
sort(b+,b++m);
hh=;tt=;
while (hh<=tt)
{
mid=(hh+tt)>>;
if (can(mid))
{
ans=mid;
tt=mid-;
}
else
hh=mid+;
}
printf("%I64d\n",ans);
}
# When Who Problem Lang Verdict Time Memory
20227903 2016-08-29 13:56:53 lbz007 E - Read Time GNU C++ Accepted 108 ms 1500 KB

Codeforces Round #200 (Div. 2)E的更多相关文章

  1. Codeforces Round #200 (Div. 1)A. Rational Resistance 数学

    A. Rational Resistance Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/343 ...

  2. Codeforces Round #200 (Div. 1)D. Water Tree dfs序

    D. Water Tree Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/343/problem/ ...

  3. Codeforces Round #200 (Div. 1) C. Read Time 二分

    C. Read Time Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/343/problem/C ...

  4. Codeforces Round #200 (Div. 1) B. Alternating Current 栈

    B. Alternating Current Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/343 ...

  5. Codeforces Round #200 (Div. 2) C. Rational Resistance

    C. Rational Resistance time limit per test 1 second memory limit per test 256 megabytes input standa ...

  6. Codeforces Round #200 (Div. 1) BCD

    为了锻炼个人能力奋力div1 为了不做原题从200开始 B 两个电线缠在一起了 能不能抓住两头一扯就给扯分开 很明显当len为odd的时候无解 当len为偶数的时候 可以任选一段长度为even的相同字 ...

  7. Codeforces Round #200 (Div. 2)D. Alternating Current (堆栈)

    D. Alternating Current time limit per test 1 second memory limit per test 256 megabytes input standa ...

  8. Codeforces Round #200 (Div. 1) D. Water Tree(dfs序加线段树)

    思路: dfs序其实是很水的东西.  和树链剖分一样, 都是对树链的hash. 该题做法是:每次对子树全部赋值为1,对一个点赋值为0,查询子树最小值. 该题需要注意的是:当我们对一棵子树全都赋值为1的 ...

  9. Codeforces Round #200 (Div. 2) E. Read Time(二分)

    题目链接 这题,关键不是二分,而是如果在t的时间内,将n个头,刷完这m个磁盘. 看了一下题解,完全不知怎么弄.用一个指针从pre,枚举m,讨论一下.只需考虑,每一个磁盘是从右边的头,刷过来的(左边来的 ...

  10. Codeforces Round #200 (Div. 1) D Water Tree 树链剖分 or dfs序

    Water Tree 给出一棵树,有三种操作: 1 x:把以x为子树的节点全部置为1 2 x:把x以及他的所有祖先全部置为0 3 x:询问节点x的值 分析: 昨晚看完题,马上想到直接树链剖分,在记录时 ...

随机推荐

  1. Mybatis-Plus的分页插件

    使用的是:Mybatis-Plus的分页插件https://baomidou.gitee.io/mybatis-plus-doc/#/?id=%E7%AE%80%E4%BB%8B 1.Mapper.j ...

  2. spring security之Remember Me

    spring-security.xml配置 环境: spring版本:5.0.7.RELEASE spring-security.xml引入: http://www.springframework.o ...

  3. estt

    1.路由控制的定义 1.1.IP地址与路由控制 互联网是由路由器连接的网络组合而成的.为了能让数据包正确地到达目标主机,路由器必须在途中进行正确地转发.这种向"正确的方法"转发数据 ...

  4. Laravel 队列使用

    触发 任务的触发,主要的实现是在IlluminateFoundationBusDispatchesJobs这个trait中实现的,其只包含两个方法 protected function dispatc ...

  5. 在dataframe添加1行(首行,或者尾部),且不覆盖

    如果直接用下面的代码添加第1行,则会覆盖掉原来的第1行. #指定位置增加一行: df.loc[0]={'a':1,'b':2} 正确方法: 新建一个同样的 dataframe, 然后合并两个dataf ...

  6. react router为什么推荐使用browserHistory而不推荐hashHistory?

    首先 browserHistory 其实使用的是 HTML5 的 History API,浏览器提供相应的接口来修改浏览器的历史记录:而 hashHistory 是通过改变地址后面的 hash 来改变 ...

  7. ES常见问题整理

    1.集群状态red.yellow处理方法 1.red表示主分片数据不完整,通常时由于某个索引的主分片为分片unassigned,找出这个分片未分配的原因,解决即可: curl -XGET http:/ ...

  8. Git 常用资源

    库管理 克隆库 git clone https://github.com/php/php-src.git git clone --depth=1 https://github.com/php/php- ...

  9. Picaso完美兼容OkHttp3.3,缓存优化两不误 - Tamic Developer"s Blog

    为何在Fresco,Glide这么强大的背景下,我又想起了当初的Picasso,又为何写这篇文章?是因为最近项目采用了square公司的RxAndroid,Retrfit和OKhttp, 不得不联想到 ...

  10. Mac开发环境部署

    1. 安装 Xcode command line tools xcode-select --install 2. 安装 Homebrew 安装 Homebrew 之前,必须先安装 Xcode Comm ...