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的更多相关文章

  1. UVALive 6656 Watching the Kangaroo --二分

    题意:给你一些区间,再查询一些点,问这些点与所有区间形成的最小距离的最大值.最小距离定义为:如果点在区间内,那么最小距离为0,否则为min(pos-L[i],R[i]-pos). 解法:当然要排个序, ...

  2. UVa 12715 Watching the Kangaroo(二分)

    题意:n条线段(n <= 100000) (L<=R <= 1e9) ,m组询问(m <= 100000) 每次询问一个点的覆盖范围的最大值.一个点x对于一条包括其的线段,覆盖 ...

  3. 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 ...

  4. Exercises - Kangaroo

    Write a definition for a class named Kangaroo with the following methods: An __init__ method that in ...

  5. 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 ...

  6. Uva 10339 - Watching Watches【数论,暴力】

    题目链接:10339 - Watching Watches 题意:两个时钟,一个每天慢a秒,一个每天慢b秒,问两钟重新相遇的时刻 1圈有12 * 60 * 60秒,然后1圈 / abs(a - b), ...

  7. Error watching file for changes: EMFILE

    运行reactnative项目时在编译过程中报错 Error watching file for changes: EMFILE 故障原因: 是升级后watchman不可用了,需要重装watchman ...

  8. 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 ...

  9. 每日英语: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 ...

随机推荐

  1. Entity Framework Core 2.0 中使用LIKE 操作符

    Entity Framework Core 2.0 中使用LIKE 操作符 不定时更新翻译系列,此系列更新毫无时间规律,文笔菜翻译菜求各位看官老爷们轻喷,如觉得我翻译有问题请挪步原博客地址 本博文翻译 ...

  2. Angular 新手容易碰到的坑

    Q1.<div ng-include="views/user/show.html"></div> 错在哪里? 如果你这么写过,会发现这个位置啥也没有加载出来 ...

  3. 《个人-GIT使用方法》

    使用GIT版本控制工具及基本使用方法(安装,新建,推送,拉取),托管平台的使用方法. Git 常用命令 git init here -- 创建本地仓库(repository),将会在文件夹下创建一个 ...

  4. RMI和socket详解

    详见: http://blog.yemou.net/article/query/info/tytfjhfascvhzxcytp58   一般来说,基于CS(client-server)软件架构的开发技 ...

  5. JVM和java应用服务器调优

    详见:http://blog.yemou.net/article/query/info/tytfjhfascvhzxcyt413 对于调优这个事情来说,一般就是三个过程: 性能监控:问题没有发生,你并 ...

  6. LDMIA、LDMIB、LDMDB、LDMDA、STMIA、LDMFD、LDMFA、LDMED、LDMEA指令详解

    简介: ARM指令中多数据传输共有两种: LDM:(load  much)多数据加载,将地址上的值加载到寄存器上 STM:(store much)多数据存储,将寄存器的值存到地址上 主要用途:现场保护 ...

  7. cobbler部署安装CentOS6.8

    Linux运维:cobbler : 矮哥linux运维群:93324526 学习cobbler的话,必须先搞懂kickstart,原理不是,不懂如何排错. kickstart部署请点击这里 1. Co ...

  8. Java 多线程(二) 线程的实现

    线程的实现 在Java中通过run方法为线程指明要完成的任务,有两种技术来为线程提供run方法: 1.继承Thread类并重写它的run方法.之后创建这个子类的对象并调用start()方法. 2.通过 ...

  9. Java中equals和==之间的区别

    今天在写表达式求值的时候,发现了equals和==||!=和!equals()之间是不一样的. 我就从网上搜了搜关于这方面的知识,然后在下面做一个总结: Java中有两类数据类型: 基本数据类型(Pr ...

  10. 201521123016《java程序设计》第4周学习总结

    1. 本周学习总结 2. 书面作业 注释的应用 使用类的注释与方法的注释为前面编写的类与方法进行注释,并在Eclipse中查看.(截图) 面向对象设计(大作业1,非常重要) 2.1 将在网上商城购物或 ...