6656 Watching the Kangaroo
6656 Watching the Kangaroo
Day by day number of Kangaroos is decreasing just like
tiger, whale or lions. So I decided to make them a sanctuary
where they will live peacefully. I do not let visitors go
near them. So I planted some display screen outside the
sanctuary. For this problem, you may assume the sanctuary
to be a long line of 1000000000 unit distance. The leftmost
position is marked with 0 and the rightmost position with
1000000000. There are at most 100000 cameras on this line.
Each of the cameras is described with (L; R) which means
that camera covers a range from position L to position R
inclusive. Each of the cameras has their associated display
screens outside where the visitors can see the Kangaroos.
Now for the convenience of the spectators we announce time to time: \Kangaroo appears in Screen
3", \Kangaroo appears in Screen 7" and so on. I have some employees who continuously monitor the
position of Kangaroos and inform the system (here position is a marker). The system chooses the best
screen to display that animal based on the coverage. The coverage of a screen for a position x is dened
as follows:
If the position x is outside the range of that screen (i.e. x < L or x > R) then the coverage is zero.
Otherwise the coverage is min(x L; R x).
An example will make it clear:
Suppose there are four screens covering the range (7, 15), (14, 100), (8, 10) and (1, 11). Now say
one Kangaroo appears at x = 10.
First screen has coverage of 3 unit around x = 10. Because x = 10 is within (7, 15) and min(10
7; 15 10) = min(3; 5) = 3.
Second screen has coverage of 0 unit around x = 10. Because x = 10 does not belong to the range
(14, 100).
Third screen has coverage of 0 unit around x = 10. Because though x = 10 is within (8, 10) but
min(10 8; 10 10) = 0.
Fourth screen has coverage of 1 unit around x = 10. Because x = 10 is within (1, 11) and min(10
1; 11 10) = 1.
So which one is better? Obviously the rst one, as it has the maximum coverage.
So you are given the ranges of the screens and the positions the kangaroo appears. For each position
of the Kangaroo you are to tell me the maximum coverage you can have with any of the screens.
Input
First line of the test le contains T (T 3), number of test cases. Hence T cases follow. For each case
you are given N, M in the rst line; N is the number of screens and M is the number of Kangaroo
appearance (1 N; M 100000). In the next N lines you are given the range of screens L R
(0 L R 1000000000). Next M lines contain the position of the Kangaroo | an integer x
(0 x 1000000000).
Output
For each case print the case number. Hence print M lines, i-th containing the maximum coverage you
can have around i-th Kangaroo.
Warning: The judge input le is around 6 MB. So use faster I/O functions.
Sample Input
1
3 2
7 15
14 100
1 11
10
120
Sample Output
Case 1:
3
0
想不到
#include <iostream>
#include <algorithm>
#include <cstdio>
#define MAXN 100010
#define INF 0x7fffffff
using namespace std;
typedef struct point
{
int l,r;
} point;
point p[];
int n,x;
int fun(int s)
{
if (s<||s>=n) return ;
if (x<p[s].l||p[s].r<x) return ;
return min(x-p[s].l,p[s].r-x);
}
bool cmp(point x,point y)
{
if(x.l==y.l)return x.r>y.r;
return x.l<y.l;
}
int main()
{
int T,i,m,j,nu,l,r,mid;
scanf("%d",&T);
for(i=; i<=T; i++)
{
scanf("%d%d",&n,&m);
for(j=; j<n; j++)
scanf("%d%d",&p[j].l,&p[j].r);
sort(p,p+n,cmp);
nu=;
for(j=; j<n; j++)
{
if(p[j].r>p[nu-].r)
p[nu++]=p[j];
}
n=nu;
printf("Case %d:\n",i);
while(m--)
{
l=,r=n-;
scanf("%d",&x);
while(l<=r)
{
mid=(l+r)>>;
if(x>p[mid].r||(x<=p[mid].r&&x>=p[mid].l&&x-p[mid].l>=p[mid].r-x))
l=mid+;
else r=mid-;
}
printf("%d\n",max(fun(l),fun(r)));
}
}
}
6656 Watching the Kangaroo的更多相关文章
- UVALive 6656 Watching the Kangaroo --二分
题意:给你一些区间,再查询一些点,问这些点与所有区间形成的最小距离的最大值.最小距离定义为:如果点在区间内,那么最小距离为0,否则为min(pos-L[i],R[i]-pos). 解法:当然要排个序, ...
- UVa 12715 Watching the Kangaroo(二分)
题意:n条线段(n <= 100000) (L<=R <= 1e9) ,m组询问(m <= 100000) 每次询问一个点的覆盖范围的最大值.一个点x对于一条包括其的线段,覆盖 ...
- Codeforces Round #219 (Div. 1) C. Watching Fireworks is Fun
C. Watching Fireworks is Fun time limit per test 4 seconds memory limit per test 256 megabytes input ...
- Exercises - Kangaroo
Write a definition for a class named Kangaroo with the following methods: An __init__ method that in ...
- Codeforces Round #219 (Div. 2) E. Watching Fireworks is Fun
http://codeforces.com/contest/373/problem/E E. Watching Fireworks is Fun time limit per test 4 secon ...
- Uva 10339 - Watching Watches【数论,暴力】
题目链接:10339 - Watching Watches 题意:两个时钟,一个每天慢a秒,一个每天慢b秒,问两钟重新相遇的时刻 1圈有12 * 60 * 60秒,然后1圈 / abs(a - b), ...
- Error watching file for changes: EMFILE
运行reactnative项目时在编译过程中报错 Error watching file for changes: EMFILE 故障原因: 是升级后watchman不可用了,需要重装watchman ...
- Gym 101981K - Kangaroo Puzzle - [玄学][2018-2019 ACM-ICPC Asia Nanjing Regional Contest Problem K]
题目链接:http://codeforces.com/gym/101981/problem/K Your friend has made a computer video game called “K ...
- 每日英语:In Digital Era, What Does 'Watching TV' Even Mean?
We spend a full five hours and 16 minutes a day in front of a screen, and that's without even turnin ...
随机推荐
- MemCache在Windows环境下的搭建及启动
MemCache在Windows环境下的搭建及启动 一.memcache服务器端的安装 1.下载memcached的安装包,memcached_en32or64.zip,下载链接:http://pan ...
- MyBatis框架知识整理
MyBatis框架 一.介绍: MyBatis实际上是Ibatis3.0版本以后的持久化层框架[也就是和数据库打交道的框架]! 和数据库打交道的技术有: 原生的JDBC技术---> Spring ...
- python appium 操作app
下面是一些Python脚本中操作app的用法: 检查app安装情况(返回true/false), driver.is_app_installed(package_name) 安装app driver. ...
- 转:swagger 入门
前言 swagger ui是一个API在线文档生成和测试的利器,目前发现最好用的. 为什么好用?Demo 传送门 支持API自动生成同步的在线文档 这些文档可用于项目内部API审核 方便测试人员了解A ...
- MacOS下免密码ssh登陆
由于配置过程中需要频繁的进行ssh连接到开发服务器执行命令以及通过scp命令向服务器拷贝文件等依赖ssh连接的操作.所以,配置本地环境跟服务器之间的ssh免密码连接可以有效的提升工作效率. ...
- 个人作业3——个人总结(Alpha阶段)
个人总结 在Alpha冲刺阶段中,我们团队基本完成了项目的大致基础框架,还有很多不足需要更多的时间来让我们做得更好. 对我个人而言,Alpha冲刺阶段是一个强度很大的阶段,每天都在吸收新的知识,团队也 ...
- 第07周-集合与GUI
1. 本周作业简评与建议 本周8分以上的同学有32人(占1/4),其中9分以上的同学有13人(占1/10).大作业未完成的最高评分一般高于6分.被认定为抄袭的为-10分.请大家认真完成大作业,后面每周 ...
- 201521044091 《Java学习笔记》 第六周学习总结
1. 本周学习总结 1.1 面向对象学习暂告一段落,请使用思维导图,以封装.继承.多态为核心概念画一张思维导图,对面向对象思想进行一个总结.注1:关键词与内容不求多,但概念之间的联系要清晰,内容覆盖面 ...
- Cookie和Session总结
Cookie概述 Cookie是什么? Cookie是一小段文本信息,伴随着用户请求和页面在Web服务器和浏览器之间传递.Cookie包含每次用户访问站点时Web应用程序都可以读取 ...
- java课程设计——猜数游戏
1.团队课程设计博客链接 http://www.cnblogs.com/springbreezemiles/p/7064135.html 2.个人负责模块或任务说明 本人任务: 编写主界面以及排行榜代 ...