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. 利用wireshark任意获取qq好友IP实施精准定位

    没事玩一把,感觉还挺有趣,首先打开wireshark: 不管你连接的什么网,如图我连接的是WLAN,双击进入如图界面: ctrl-f进行搜索:如图 选择分组详情,字符串,并输入020048.这时候你就 ...

  2. beanshell postprocessor解决编码

    beanshell postprocessor  String s=new String(prev.getResponseData(),"UTF-8");        char  ...

  3. postman 第1节 安装启动(转)

    安装: 1.mac app安装 浏览器访问https://www.getpostman.com/apps,选择Get the Mac App,下载安装即可 2.chrome app安装 浏览器访问ht ...

  4. Day1 - 服务器硬件基础

    1.1 关于运维人员 1.1.1 运维的职责 1.保证服务器7*24小时 运行 2.保证数据不能丢 3.提高用户的体验(网站打开的速度) 1.1.2 运维原则 简单.易用.高效  === 简单.粗暴 ...

  5. TCP/IP协议栈模型

    OSI七层模型介绍: 下面4层(物理层.数据链路层.网络层和传输层)主要提供数据传输和交换功能,即以节点到节点之间的通信为主:第4层作为上下两部分的桥梁,是整个网络体系结构中最关键的部分:而上3层(会 ...

  6. C++内存布局详解

    一个由C/C++编译的程序除了存放函数二进制代码的程序代码段(code段)外,数据占用的内存大致分为以下几个部分: 1.栈区(stack) 存放局部变量.函数参数.返回数据.返回地址等.系统自动分配释 ...

  7. JS基础-----JS中的分支结构及循环结构

    [分支结构] 一.if-else结构 1.结构的写法:if(判断条件){ //条件为true时,执行if的{} }else{ //条件为false时,执行else的{} } 2.注意事项 ①else语 ...

  8. java 读写锁详解

    详见:http://blog.yemou.net/article/query/info/tytfjhfascvhzxcyt124 在java多线程中,为了提高效率有些共享资源允许同时进行多个读的操作, ...

  9. 探索 Java 热部署

    在 JAVA 开发领域,热部署一直是一个难以解决的问题,目前的 JAVA 虚拟机只能实现方法体的修改热部署,对于整个类的结构修改,仍然需要重启虚拟机,对类重新加载才能完成更新操作.对于某些大型的应用来 ...

  10. JOptionPane弹框常用实例

    最近在做swing程序中遇到使用消息提示框的,JOptionPane类其中封装了很多的方法. 很方便的,于是就简单的整理了一下. 1.1 showMessageDialog 显示一个带有OK 按钮的模 ...