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)));
}
}
}

最新文章

  1. 5 Hbase
  2. SQL Server 2008 R2——以特定符号出现的次数来判断当前内容所在的层次
  3. win8 vs2010 openni2 配置
  4. phpDocumentor 注释语法详解
  5. Selenium2+python自动化7-xpath定位
  6. 还在用GCD?来看看NSOperation吧
  7. WebForm Repeater的事件、后天数据展示--2017年1月8日
  8. C#简单邮件发送
  9. return;,return false,return true----------浅析
  10. 自己实现的Boost库中的lexical_cast随意类型转换
  11. 无源RS232转RS485(转)
  12. Linuxc - 标准输入流、标准输出流、标准错误流
  13. 2018.3.6学习java的第一天
  14. JavaScript基础知识必知!!!
  15. Python安装第三方包(模块/工具)出现链接超时,网速慢,安装不上的问题如何解决
  16. Windows 与Office 镜像的区别
  17. mvc 中合并两个list集合
  18. android图片绘制
  19. ADALINE小demo
  20. 架构师养成记--37.简单shell编程

热门文章

  1. Tensorflow开发环境配置及其基本概念
  2. hdu 6199 沈阳网络赛---gems gems gems(DP)
  3. h5audio标签
  4. Maven Scope取值的含义
  5. 09 Linear Regression
  6. Mac/Windows开发跨平台.NET Core 控制台程序
  7. 201521123103 《Java学习笔记》 第六周学习总结
  8. 201521123055 《Java程序设计》第5周学习总结
  9. 201521123109《java程序设计》第四周学习总结
  10. 201521123103 《Java学习笔记》第二周学习笔记