【BZOJ】1660: [Usaco2006 Nov]Bad Hair Day 乱发节(单调栈)
http://www.lydsy.com/JudgeOnline/problem.php?id=1660
单调栈裸题。。累计比每一个点高的个数即可。
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define for1(i,a,n) for(int i=(a);i<=(n);++i)
#define for2(i,a,n) for(int i=(a);i<(n);++i)
#define for3(i,a,n) for(int i=(a);i>=(n);--i)
#define for4(i,a,n) for(int i=(a);i>(n);--i)
#define CC(i,a) memset(i,a,sizeof(i))
#define read(a) a=getint()
#define print(a) printf("%d", a)
#define dbg(x) cout << #x << " = " << x << endl
#define printarr(a, n, m) rep(aaa, n) { rep(bbb, m) cout << a[aaa][bbb]; cout << endl; }
inline const int getint() { int r=0, k=1; char c=getchar(); for(; c<'0'||c>'9'; c=getchar()) if(c=='-') k=-1; for(; c>='0'&&c<='9'; c=getchar()) r=r*10+c-'0'; return k*r; }
inline const int max(const int &a, const int &b) { return a>b?a:b; }
inline const int min(const int &a, const int &b) { return a<b?a:b; }
const bool cmp(const int &a, const int &b) { return a>=b; }
const int N=80006;
int s[N], top, h[N], n;
long long ans; void update(int x) {
while(top && h[x]>=s[top]) --top;
ans+=top;
s[++top]=h[x];
} int main() {
read(n);
for1(i, 1, n) read(h[i]);
for1(i, 1, n) update(i);
printf("%lld", ans);
return 0;
}
Description

Input
* Line 1: 牛的数量 N。
* Lines 2..N+1: 第 i+1 是一个整数,表示第i头牛的高度。
Output
* Line 1: 一个整数表示c[1] 至 c[N]的和。
Sample Input
10
3
7
4
12
2
输入解释:
六头牛排成一排,高度依次是 10, 3, 7, 4, 12, 2。
Sample Output
3+0+1+0+1=5
HINT
Source
【BZOJ】1660: [Usaco2006 Nov]Bad Hair Day 乱发节(单调栈)的更多相关文章
- BZOJ 1660: [Usaco2006 Nov]Bad Hair Day 乱发节( 单调栈 )
维护一个h严格递减的栈 , 出栈时计算一下就好了.. ------------------------------------------------------------------------- ...
- BZOJ 1660: [Usaco2006 Nov]Bad Hair Day 乱发节
Description Input * Line 1: 牛的数量 N. * Lines 2..N+1: 第 i+1 是一个整数,表示第i头牛的高度. Output * Line 1: 一个整数表示c[ ...
- BZOJ 1660 [Usaco2006 Nov]Bad Hair Day 乱发节:单调栈
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1660 题意: 有n头牛,身高分别为h[i]. 它们排成一排,面向右边.第i头牛可以看见在它 ...
- bzoj 1660: [Usaco2006 Nov]Bad Hair Day 乱发节【单调栈】
开一个单调递减的单调栈,然后用sum数组维护每个点的答案,新加点的时候一边退栈一边把退掉的点的sum加进来 #include<iostream> #include<cstdio> ...
- BZOJ1660: [Usaco2006 Nov]Bad Hair Day 乱发节(单调栈)
题意 题目链接 Sol 单调栈板子题.. 找到向左第一个比他大的位置,然后判断一下就可以了 #include<bits/stdc++.h> //#define int long long ...
- 1660: [Usaco2006 Nov]Bad Hair Day 乱发节
1660: [Usaco2006 Nov]Bad Hair Day 乱发节 Time Limit: 2 Sec Memory Limit: 64 MB Submit: 665 Solved: 31 ...
- 【BZOJ 1660】 [Usaco2006 Nov]Bad Hair Day 乱发节
1660: [Usaco2006 Nov]Bad Hair Day 乱发节 Time Limit: 2 Sec Memory Limit: 64 MB Submit: 678 Solved: 32 ...
- BZOJ1660: [Usaco2006 Nov]Bad Hair Day 乱发节
1660: [Usaco2006 Nov]Bad Hair Day 乱发节 Time Limit: 2 Sec Memory Limit: 64 MBSubmit: 606 Solved: 289 ...
- [Usaco2006 Nov]Bad Hair Day 乱发节
Time Limit: 2 Sec Memory Limit: 64 MBSubmit: 1268 Solved: 625[Submit][Status][Discuss] Description ...
随机推荐
- MySQL 官方文档
MySQL 5.6 Reference Manual Preface and Legal Notices 1 General Information 2 Installing and Upgradin ...
- Openerp 中打开 URL 的三种 方法
来自:http://shine-it.net/index.php/topic,8013.0.html 最近总结了,Openerp 中打开 URL 的三种 方法: 一.在form view 添加 < ...
- wait & waitpid 以及子进程传给父进程的信号分析
wait() 和 waitpid() wait() 系统调用挂起调用进程的执行直到有一个孩子终止.调用 wait(&status) 等价于: waitpid(-1, &status, ...
- 深入RecyclerView-为什么要使用ItemDecoration
Part 1:不要用view做分割线 首先,什么是ItemDecoration?来看看官网是如何解释的. ItemDecoration允许从adapter的数据集合中为特定的item视图添加特性的绘制 ...
- CentOS连接网络注意事项
连接网络,系统中这两个服务需要启动 可以看到右上角网络连接成功了
- 教你在Ubuntu系统下保存屏幕亮度设置
本文保留屏幕亮度方法适合使用笔记本的朋友,大家都知道,过亮的屏幕不但刺眼而且缩短LCD屏幕寿命,不幸的是,Ubuntu默认关机后并不保存当前屏幕亮度配置数据,每次开机都要重新设置亮度,很不方便.本文 ...
- Python 3.x 连接 pymysql 数据库
首先,需要安装库: 使用 pycharm IDE,如PyCharm,可以使用 project python 安装第三方模块. [File] >> [settings] >> [ ...
- 从程序员到CTO的Java技术路线图 JAVA职业规划 JAVA职业发展路线图 系统后台框架图、前端工程师技能图 B2C电子商务基础系统架构解析
http://zz563143188.iteye.com/blog/1877266在技术方面无论我们怎么学习,总感觉需要提升自已不知道自己处于什么水平了.但如果有清晰的指示图供参考还是非常不错的,这样 ...
- ceph之查看osd上pg的分布
一.概述 osd上pg的分布决定了数据分布的均匀与否,所以能直观的看到pg到osd的上分布是很有必要的: ceph只身提供了相关的命令: #ceph pg ls-by-osd.{osd_id} #fo ...
- NPOI workbook.RemoveSheetAt(0); 删除sheet页 次序 sheettmpRequire.CopySheet("Require", true);
假如workbook的sheet页有多个 要删除第一个第二个 workbook.RemoveSheetAt(0); workbook.RemoveSheetAt(1); 这样写不行 这样写会删除第一个 ...