Codeforces Round #200 (Div. 2)E
题意:有一个数组,很多指针指在这个数组上,每次每个指针可以向左或向右移动一个位置。给出一些需要访问的位置,问访问用的最少时间。
一个指针只可能转一次方向。二分答案。
#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的更多相关文章
- Codeforces Round #200 (Div. 1)A. Rational Resistance 数学
A. Rational Resistance Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/343 ...
- 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/ ...
- 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 ...
- Codeforces Round #200 (Div. 1) B. Alternating Current 栈
B. Alternating Current Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/343 ...
- 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 ...
- Codeforces Round #200 (Div. 1) BCD
为了锻炼个人能力奋力div1 为了不做原题从200开始 B 两个电线缠在一起了 能不能抓住两头一扯就给扯分开 很明显当len为odd的时候无解 当len为偶数的时候 可以任选一段长度为even的相同字 ...
- 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 ...
- Codeforces Round #200 (Div. 1) D. Water Tree(dfs序加线段树)
思路: dfs序其实是很水的东西. 和树链剖分一样, 都是对树链的hash. 该题做法是:每次对子树全部赋值为1,对一个点赋值为0,查询子树最小值. 该题需要注意的是:当我们对一棵子树全都赋值为1的 ...
- Codeforces Round #200 (Div. 2) E. Read Time(二分)
题目链接 这题,关键不是二分,而是如果在t的时间内,将n个头,刷完这m个磁盘. 看了一下题解,完全不知怎么弄.用一个指针从pre,枚举m,讨论一下.只需考虑,每一个磁盘是从右边的头,刷过来的(左边来的 ...
- Codeforces Round #200 (Div. 1) D Water Tree 树链剖分 or dfs序
Water Tree 给出一棵树,有三种操作: 1 x:把以x为子树的节点全部置为1 2 x:把x以及他的所有祖先全部置为0 3 x:询问节点x的值 分析: 昨晚看完题,马上想到直接树链剖分,在记录时 ...
随机推荐
- JVM常见问题分析
JVM常见问题分析 启动,并且去查看日志 ./startup.sh && tail -f ../logs/catalina.out 常见有有以下几个问题: 1.java.lang.Ou ...
- CF-1102E-Monotonic Renumeration
比较可惜昨天比赛的时候时间不够了,在比赛结束之后五分钟找出了bug提交通过了.然并软: 首先这题说b数组的后一项要么等于前一项,要么等于前一项加一,而且如果a[i] == a[j] ,那么b[i] = ...
- App Store成绞肉机 让创业者止步
Store成绞肉机 让创业者止步" title="App Store成绞肉机 让创业者止步"> 曾几何时,苹果App Store一直被称之为创业者的天堂.似乎只要灵 ...
- python标准库-array 模块
原文地址:http://www.bugingcode.com/blog/python_module_array.html array 模块是python中实现的一种高效的数组存储类型.它和list相似 ...
- MyBatis学习总结之一对多映射
1.首先创建2张表:students 和grades create table grades( gid ) primary key, gname varchar() ); create table s ...
- SpringMVC_Day01
项目结构 //SpringMVC配置文件 <?xml version="1.0" encoding="UTF-8"?> <!-- spring ...
- 查漏补缺:进程间通信(IPC):管道
管道是UNIX系统IPC的最古老形式,所有UNIX系统都提供此种通信机制.管道有以下两种局限性: (1)历史上,管道是半双工的(即数据只能在一个方向上流动). (2)管道只能在具有公共先祖的两个进程之 ...
- Github 绑定域名添加https的方法 2019年9月更新
官方教程 https://help.github.com/en/articles/using-a-custom-domain-with-github-pages 打开 https://github.c ...
- Gif截屏工具 - GifCam
如果你需要录制截屏并保存成gif图片格式,那么你一定不能错过GifCam这个神奇的小工具.它虽然只有600K,但功能不可小觑. GifCam (Gif相机) 是一款免费且非常优秀的视频录制/剪辑的GI ...
- Python计算给定日期的周内的某一天
先理一下思路:1.weekday会根据某个日期返回0到6的一个数字来表示星期几对吧,0==星期一我们来列一个表: [0,1,2,3,4,5,6] 2.知道了星期几之后,你可以计算出那一周相对于这个0到 ...