[Usaco2006 Mar]Mooo 奶牛的歌声
Description
Farmer John's N (1 <= N <= 50,000) cows are standing in a very straight row and mooing. Each cow has a unique height h in the range 1..2,000,000,000 nanometers (FJ really is a stickler for precision). Each cow moos at some volume v in the range 1..10,000. This "moo" travels across the row of cows in both directions (except for the end cows, obviously). Curiously, it is heard only by the closest cow in each direction whose height is strictly larger than that of the mooing cow (so each moo will be heard by 0, 1 or 2 other cows, depending on not whether or taller cows exist to the mooing cow's right or left). The total moo volume heard by given cow is the sum of all the moo volumes v for all cows whose mooing reaches the cow. Since some (presumably taller) cows might be subjected to a very large moo volume, FJ wants to buy earmuffs for the cow whose hearing is most threatened. Please compute the loudest moo volume heard by any cow.
Farmer John的N(1<=N<=50,000)头奶牛整齐地站成一列“嚎叫”。每头奶牛有一个确定的高度h(1<=h<=2000000000),叫的音量为v (1<=v<=10000)。每头奶牛的叫声向两端传播,但在每个方向都只会被身高严格大于它的最近的一头奶牛听到,所以每个叫声都只会 被0,1,2头奶牛听到(这取决于它的两边有没有比它高的奶牛)。 一头奶牛听到的总音量为它听到的所有音量之和。自从一些奶牛遭受巨大的音量之后,Farmer John打算买一个耳罩给被残害得最厉 害的奶牛,请你帮他计算最大的总音量。
Input
Line 1: A single integer, N.
Lines 2..N+1: Line i+1 contains two space-separated integers, h and v, for the cow standing at location i.
第1行:一个正整数N.
第2到N+1行:每行包括2个用空格隔开的整数,分别代表站在队伍中第i个位置的奶牛的身高以及她唱歌时的音量.
Output
- Line 1: The loudest moo volume heard by any single cow.
队伍中的奶牛所能听到的最高的总音量.
Sample Input
3
4 2
3 5
6 10
Sample Output
7
HINT
队伍中的第3头奶牛可以听到第1头和第2头奶牛的歌声,于是她能听到的总音量为2+5=7.虽然她唱歌时的音量为10,但并没有奶牛可以听见她的歌声.
单调栈,正着一遍反着一遍,维护严格递减即可
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define inf 0x7f7f7f7f
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
inline int read(){
int x=0,f=1;char ch=getchar();
for (;ch<'0'||ch>'9';ch=getchar()) if (ch=='-') f=-1;
for (;ch>='0'&&ch<='9';ch=getchar()) x=(x<<1)+(x<<3)+ch-'0';
return x*f;
}
inline void print(int x){
if (x>=10) print(x/10);
putchar(x%10+'0');
}
const int N=5e4;
struct AC{
int high,val;
void join(){high=read(),val=read();}
}cow[N+10];
int stack[N+10],val[N+10];
int main(){
int n=read(),ans=0;
for (int i=1;i<=n;i++) cow[i].join();
for (int i=1,top=0;i<=n;i++){
while (top&&cow[i].high>cow[stack[top]].high) val[i]+=cow[stack[top--]].val;
stack[++top]=i;
}
for (int i=n,top=0;i;i--){
while (top&&cow[i].high>cow[stack[top]].high) val[i]+=cow[stack[top--]].val;
stack[++top]=i;
}
for (int i=1;i<=n;i++) ans=max(ans,val[i]);
printf("%d\n",ans);
return 0;
}
[Usaco2006 Mar]Mooo 奶牛的歌声的更多相关文章
- Bzoj 1657: [Usaco2006 Mar]Mooo 奶牛的歌声 单调栈
1657: [Usaco2006 Mar]Mooo 奶牛的歌声 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 631 Solved: 445[Submi ...
- BZOJ1657: [Usaco2006 Mar]Mooo 奶牛的歌声
1657: [Usaco2006 Mar]Mooo 奶牛的歌声 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 489 Solved: 338[Submi ...
- 1657: [Usaco2006 Mar]Mooo 奶牛的歌声
1657: [Usaco2006 Mar]Mooo 奶牛的歌声 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 526 Solved: 365[Submi ...
- [Usaco2006 Mar]Mooo 奶牛的歌声(单调栈裸题)
1657: [Usaco2006 Mar]Mooo 奶牛的歌声 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 961 Solved: 679[Submi ...
- [BZOJ1657] [Usaco2006 Mar] Mooo 奶牛的歌声 (单调栈)
Description Farmer John's N (1 <= N <= 50,000) cows are standing in a very straight row and mo ...
- 【BZOJ】1657: [Usaco2006 Mar]Mooo 奶牛的歌声(单调栈)
http://www.lydsy.com/JudgeOnline/problem.php?id=1657 这一题一开始我想到了nlog^2n的做法...显然可做,但是麻烦.(就是二分+rmq) 然后我 ...
- BZOJ 1657 [Usaco2006 Mar]Mooo 奶牛的歌声:单调栈【高度序列】
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1657 题意: Farmer John的N(1<=N<=50,000)头奶牛整齐 ...
- bzoj 1657 [Usaco2006 Mar]Mooo 奶牛的歌声——单调栈水题
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1657 #include<iostream> #include<cstdio ...
- bzoj 1657: [Usaco2006 Mar]Mooo 奶牛的歌声【单调栈】
先考虑只能往一边传播,最后正反两边就行 一向右传播为例,一头牛能听到的嚎叫是他左边的牛中与高度严格小于他并且和他之间没有更高的牛,用单调递减的栈维护即可 #include<iostream> ...
随机推荐
- win8,win10里面内置的IE浏览器网银无法输入密码
win8,win10里面内置的IE浏览器网银无法输入密码,安装控件也没效果,部分网银直接导致IE崩溃,只需要简单设置即可解决. 方法/步骤 1 打开IE浏览器,点击右上角的小齿轮图标,在下拉菜单中 ...
- C#中list比数组效率低多少
对于List,即长度不确定的数组而言,十万笔数据*12倍,就是120万笔数据,只需要93ms左右 换成了二维数组,效果也是差不多,78ms,可见list的效率只比double差一点点
- Office WORD如何简繁转换
选中要转换的文字,工具-语言,中文简繁转换.
- win8系统 如何不显示这台电脑的文件夹
在win8系统中,默认有下面这种文件夹 只要打开注册表编辑器,找到下面所示的项目,删除所有子文件夹即可(最后剩下一个DelegateFolders不用管) [HKEY_LOCAL_MACHINE\ ...
- windows下 sqlplus / as sysdba 报ora-12560的终极解决方法
windows下 sqlplus / as sysdba 报ora-12560的终极解决方法 本文是原创文章.转载请注明出处:http://blog.csdn.net/msdnchina/articl ...
- sqoop基本 操作
列出 hive的 全部库 sqoop list-databases --connect jdbc:mysql://localhost --username hive --password hive 列 ...
- MySQL基础笔记(六) 存储过程与函数
写在开头:本文所有的示例都是基于workers表,表中保存了某公司的员工姓名.性别.工资.年龄和居住城市,如下: +----+-----------+--------+--------+------+ ...
- 使用RNN解决句子对匹配问题的常见网络结构
/* 版权声明:能够随意转载,转载时请标明文章原始出处和作者信息 .*/ author: 张俊林 除了序列标注问题外,句子对匹配(Sentence Pair Matching)问题也是NLP中非经常见 ...
- leveldb学习:DBimpl
leveldb将数据库的有关操作都定义在了DB类,它负责整个系统功能组件的连接和调用.是整个系统的脊柱. level::DB是一个接口类,真正的实如今DBimpl类. 作者在文档impl.html中描 ...
- python 深浅复制与指针内存
Python是一门非常好的语言,他的长处在于拥有巨大灵活性的同一时候也拥有无比的严谨性,其它语言规定了非常多语法.告诉你什么情况下,语法就是这种,而Python却用非常少的规定,延伸出非常多语法,有些 ...