BZOJ1660: [Usaco2006 Nov]Bad Hair Day 乱发节
1660: [Usaco2006 Nov]Bad Hair Day 乱发节
Time Limit: 2 Sec Memory Limit: 64 MB
Submit: 606 Solved: 289
[Submit][Status]
Description
.jpg)
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
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<string>
#define inf 1000000000
#define maxn 80000+100
#define maxm 500+100
#define eps 1e-10
#define ll long long
#define pa pair<int,int>
using namespace std;
inline int read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=*x+ch-'';ch=getchar();}
return x*f;
}
int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
int n=read(),a[maxn],sta[maxn];
for(int i=;i<=n;i++)a[i]=read();
a[n+]=inf;
int top=;
ll ans=;
for(int i=;i<=n+;i++)
{
while(top>&&a[i]>=a[sta[top]])ans+=i-sta[top--]-;
sta[++top]=i;
}
printf("%lld\n",ans);
return ;
}
BZOJ1660: [Usaco2006 Nov]Bad Hair Day 乱发节的更多相关文章
- BZOJ1660: [Usaco2006 Nov]Bad Hair Day 乱发节(单调栈)
题意 题目链接 Sol 单调栈板子题.. 找到向左第一个比他大的位置,然后判断一下就可以了 #include<bits/stdc++.h> //#define int long long ...
- BZOJ 1660: [Usaco2006 Nov]Bad Hair Day 乱发节( 单调栈 )
维护一个h严格递减的栈 , 出栈时计算一下就好了.. ------------------------------------------------------------------------- ...
- 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 ...
- 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 单调栈裸题..累计比每一个点高的个数即可. #include <cstdio> # ...
- BZOJ 1660 [Usaco2006 Nov]Bad Hair Day 乱发节:单调栈
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1660 题意: 有n头牛,身高分别为h[i]. 它们排成一排,面向右边.第i头牛可以看见在它 ...
- [Usaco2006 Nov]Bad Hair Day 乱发节
Time Limit: 2 Sec Memory Limit: 64 MBSubmit: 1268 Solved: 625[Submit][Status][Discuss] Description ...
- bzoj 1660: [Usaco2006 Nov]Bad Hair Day 乱发节【单调栈】
开一个单调递减的单调栈,然后用sum数组维护每个点的答案,新加点的时候一边退栈一边把退掉的点的sum加进来 #include<iostream> #include<cstdio> ...
随机推荐
- MyBatis报错
1.错误描写叙述 2014-11-2 15:03:11 org.apache.catalina.core.StandardEngine start 信息: Starting Servlet Engin ...
- MYSQL 体系结构图-unzip_LRU
- Java POI导入Excel文件
今天在公司需要做个导入Excel文件的功能,所以研究了一下,参考网上的一些资料总算是做出来了,在此记录一下防止以后忘记怎么弄. 本人用的是poi3.8,所以需要的JAR包如下: poi-3.8.jar ...
- java mysql驱动
mysql驱动方式有三种, 1.第一种是先把jar包放在项目的目录下,通过添加jar包,是使用相对地址的,这样把项目复制到其它电脑也可以用 2.第二种方法是导入外部的jar包,是绝对地址,如果项目要复 ...
- 这10篇 iOS 热文,你别错过哦
<移动开发必读书单> 某一领域的技术人,在他的职业生涯中,一定有一些绕不过去的技术和非技术的知识.有的时候,靠自己摸索.到处偷师,倒也能掌握.但是,这些别人早就趟过去的坎,大多已经有了非常 ...
- Volley的基本使用(转)
Volley是Google在2003年的I/O大会上推出的通信框架,结合了AsyncHttpClient和Universal-Image-Loader的优点——简化了http的使用 + 异步加载图片的 ...
- 9.5noip模拟试题
题目名称 正确答案 序列问题 长途旅行 英文名称 answer sequence travel 输入文件名 answer.in sequence.in travel.in 输出文件名 answer.o ...
- 获取外网IP地址
public static string GetRealIP(){ string result = String.Empty; result = HttpC ...
- UISegmentControl 、UIStepper
UISegmentControl .UIStepper UISegmentControl 1. UISegmentedControl *segmentControl = [[UISegmentedCo ...
- 05_Smart-image通过SoftReference提高性能
文章导读: 文件介绍了常见的图片下载开源插件smart-image, 由于移动设备硬件受限,因此Android的相关app都要考虑到性能的关系, 所以很多的第三方插件都使用到了缓存cache技术,本人 ...