【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 ...
随机推荐
- OpenERP7.0中非admin帐号新增其它用户问题
在OpenERP7.0中,通过admin新增了一个管理员帐号,然后登录管理员帐号,再新增其它用户时提示错误,系统提示对users没有create权限. 经测试了解,是因为安装了多公司模块后,在记录规则 ...
- iOS开发之UITableView的使用
这一篇记录的是iOS开发中UITableView的使用,iOS中的UITableView跟Android中的ListView特别相似,以下用一个Demo来说明: 1.Xcode中新建projectTe ...
- if-else用法
CreateTime--2016年10月31日14:22:25Author:Marydonif-else的多种用法: //方式一 function test1 (t) { var bl = t | ...
- iOS开发-多线程开发之线程安全篇
前言:一块资源可能会被多个线程共享,也就是多个线程可能会访问同一块资源,比如多个线程访问同一个对象.同一个变量.同一个文件和同一个方法等.因此当多个线程访问同一块资源时,很容易会发生数据错误及数据不安 ...
- 零基础小白怎么用Python做表格?
用Python操作Excel在工作中还是挺常用的,因为毕竟不懂Excel是一个用户庞大的数据管理软件.本文用Python3!在给大家分享之前呢,小编推荐一下一个挺不错的交流宝地,里面都是一群热爱并在学 ...
- 【LeetCode】96. Unique Binary Search Trees (2 solutions)
Unique Binary Search Trees Given n, how many structurally unique BST's (binary search trees) that st ...
- ceph之查看osd上pg的分布
一.概述 osd上pg的分布决定了数据分布的均匀与否,所以能直观的看到pg到osd的上分布是很有必要的: ceph只身提供了相关的命令: #ceph pg ls-by-osd.{osd_id} #fo ...
- 和求余运算巧妙结合的jns指令
.text:004A78B1 and eax, 80000001h.text:004A78B6 jns short loc_4A78BD.text:004A78B8 dec eax.text:00 ...
- kong 插件开发分析
1.安装开发环境:(我这里用IntelliJ IDEA) 先安装lua 5.1和luarocks 因为kong基于openresty,openresty使用luajit luajit支持的是lua5. ...
- C#删除xml指定节点