3314: [Usaco2013 Nov]Crowded Cows
3314: [Usaco2013 Nov]Crowded Cows
Time Limit: 1 Sec Memory Limit: 128 MB
Submit: 111 Solved: 79
[Submit][Status][Discuss]
Description
Farmer John's N cows (1 <= N <= 50,000) are grazing along a one-dimensional fence. Cow i is standing at location x(i) and has height h(i) (1 <= x(i),h(i) <= 1,000,000,000). A cow feels "crowded" if there is another cow at least twice her height within distance D on her left, and also another cow at least twice her height within distance D on her right (1 <= D <= 1,000,000,000). Since crowded cows produce less milk, Farmer John would like to count the number of such cows. Please help him.
N头牛在一个坐标轴上,每头牛有个高度。现给出一个距离值D。
如果某头牛在它的左边,在距离D的范围内,如果找到某个牛的高度至少是它的两倍,且在右边也能找到这样的牛的话。则此牛会感觉到不舒服。
问有多少头会感到不舒服。
Input
* Line 1: Two integers, N and D.
* Lines 2..1+N: Line i+1 contains the integers x(i) and h(i). The locations of all N cows are distinct.
Output
* Line 1: The number of crowded cows.
Sample Input
10 3
6 2
5 3
9 7
3 6
11 2
INPUT DETAILS: There are 6 cows, with a distance threshold of 4 for feeling crowded. Cow #1 lives at position x=10 and has height h=3, and so on.
Sample Output
OUTPUT DETAILS: The cows at positions x=5 and x=6 are both crowded.
HINT
Source
题解:一个萌萌哒RMQ问题(HansBug:吐槽下翻译——输入里面明明说了the location is distinct,也就是说每只牛坐标唯一,这样子虽然没有实质性变化,但是简化了不少问题,毕竟题目说是左边和右边的牛,没说此位置上的= =),将坐标排序,然后就是区间查询最大值啦,然后没了
/**************************************************************
Problem:
User: HansBug
Language: Pascal
Result: Accepted
Time: ms
Memory: kb
****************************************************************/ var
i,j,k,l,m,n:longint;
a,b:array[..,..] of longint;
c:array[..,..] of longint;
function max(x,y:longint):longint;
begin
if x>y then max:=x else max:=y;
end;
procedure swap(var x,y:longint);
var z:longint;
begin
z:=x;x:=y;y:=z;
end;
procedure sort(l,r:longint);
var i,j,x:longint;
begin
i:=l;j:=r;x:=a[(l+r) div ,];
repeat
while a[i,]<x do inc(i);
while a[j,]>x do dec(j);
if i<=j then
begin
swap(a[i,],a[j,]);
swap(a[i,],a[j,]);
inc(i);dec(j);
end;
until i>j;
if i<r then sort(i,r);
if l<j then sort(l,j);
end;
function getmax(x,y:longint):longint;
var i:longint;
begin
if y<x then exit(-);
i:=trunc(ln(y-x+)/ln());
exit(max(c[i,x],c[i,y-trunc(exp(ln()*i))+]));
end;
begin
readln(n,m);
for i:= to n do readln(a[i,],a[i,]);
sort(,n);
for i:= to n do c[,i]:=a[i,];
for i:= to trunc(ln(n)/ln()+) do
for j:= to n-trunc(exp(ln()*i))+ do
c[i,j]:=max(c[i-,j],c[i-,j+trunc(exp(ln()*(i-)))]);
k:=;fillchar(b[],sizeof(b[]),);
for i:= to n do
begin
while (a[k,]+m)<a[i,] do inc(k);
if getmax(k,i-)>=(a[i,]*) then b[i,]:=;
end;
k:=n;fillchar(b[],sizeof(b[]),);
for i:=n- downto do
begin
while (a[k,]-m)>a[i,] do dec(k);
if getmax(i+,k)>=(a[i,]*) then b[i,]:=;
end;
l:=;for i:= to n do inc(l,(b[i,]+b[i,]) div );
writeln(l);
readln; end.
3314: [Usaco2013 Nov]Crowded Cows的更多相关文章
- BZOJ 3314: [Usaco2013 Nov]Crowded Cows( 单调队列 )
从左到右扫一遍, 维护一个单调不递减队列. 然后再从右往左重复一遍然后就可以统计答案了. ------------------------------------------------------- ...
- 【BZOJ】3314: [Usaco2013 Nov]Crowded Cows(单调队列)
http://www.lydsy.com/JudgeOnline/problem.php?id=3314 一眼就是维护一个距离为d的单调递减队列... 第一次写.....看了下别人的代码... 这一题 ...
- BZOJ 3314 [Usaco2013 Nov]Crowded Cows:单调队列
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=3314 题意: N头牛在一个坐标轴上,每头牛有个高度.现给出一个距离值D. 如果某头牛在它的 ...
- BZOJ3314: [Usaco2013 Nov]Crowded Cows
3314: [Usaco2013 Nov]Crowded Cows Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 86 Solved: 61[Subm ...
- 【BZOJ3314】 [Usaco2013 Nov]Crowded Cows 单调队列
第一次写单调队列太垃圾... 左右各扫一遍即可. #include <iostream> #include <cstdio> #include <cstring> ...
- BZOJ : [Usaco2013 Nov]Crowded 单调队列
正反两遍个来一次单调队列 DP 即可. Code: #include<cstdio> #include<deque> #include<algorithm> usi ...
- BZOJ3315: [Usaco2013 Nov]Pogo-Cow
3315: [Usaco2013 Nov]Pogo-Cow Time Limit: 3 Sec Memory Limit: 128 MBSubmit: 143 Solved: 79[Submit] ...
- BZOJ3016: [Usaco2012 Nov]Clumsy Cows
3016: [Usaco2012 Nov]Clumsy Cows Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 71 Solved: 52[Submi ...
- BZOJ 2060: [Usaco2010 Nov]Visiting Cows 拜访奶牛( dp )
树形dp..水 ------------------------------------------------------------------------ #include<cstdio& ...
随机推荐
- C# winform项目中ListView控件使用CheckBoxes属性实现单选功能
C# winform项目中ListView控件使用CheckBoxes属性实现单选功能 在做项目时需要使用ListView控件的CheckBoxes属性显示,还要在点击行时自动选中CheckBoxes ...
- 用Redis作为Mysql数据库的缓存
看到一篇不错的博文,记录下: http://blog.csdn.net/qtyl1988/article/details/39553339 http://blog.csdn.net/qtyl1988/ ...
- Pomelo的Protobuf
pomelo的protobuf实现,借助了javascript的动态性,使得应用程序可以在运行时解析proto文件,不需要进行proto文件的编译.pomelo的实现中,为了更方便地解析proto文件 ...
- 数据结构实习-迷宫(基于Qt实现)
预览效果: Maze.pro文件 #------------------------------------------------- # # Project created by QtCreator ...
- android: activity切换之效果
Activity是android应用的重要部分;为了提高用户的体验度,加了Activity之间切换的动画效果,现在介绍的一种切换动画: 是什么效果,大家自已动手测试一下便知道: 先看进入的动画: pa ...
- 转:Spring FactoryBean源码浅析
http://blog.csdn.net/java2000_wl/article/details/7410714 在Spring BeanFactory容器中管理两种bean 1.标准Java Bea ...
- Socket通信流程
Socket通信流程 HTTP 底层就是通过socket建立连接通信管道,实现数据传输 HTTP是一个TCP的传输协议(方式),它是一个可靠,安全的协议
- Linux 用键盘操作窗口
以下是我从各处搜集来的关于用键盘操作窗口信息,操作可能不是最简或者最好的,当然也可能不是最全的,以后遇到新的操作,我会即使添加,如果你有我没有列出的操作,希望你能提出,我可以加上! 我实验的操作系统是 ...
- 自定义滚动条Js简版
<!DOCTYPE html><html><head><meta charset="UTF-8"><title>自定义滚 ...
- DllRegisterServer的调用失败的问题解决方法
1'按键盘上的win+x键调出常用命令. 2'选择“命令提示符(管理员)“ 3'在”命令提示符“中输入”regsvr32 c:\Windows\SysWOW64\comdlg32.ocx“或其他ocx ...