1660: [Usaco2006 Nov]Bad Hair Day 乱发节

Time Limit: 2 Sec  Memory Limit: 64 MB
Submit: 606  Solved: 289
[Submit][Status]

Description

Input

* Line 1: 牛的数量 N。

* Lines 2..N+1: 第 i+1 是一个整数,表示第i头牛的高度。

Output

* Line 1: 一个整数表示c[1] 至 c[N]的和。

Sample Input

6
10
3
7
4
12
2

输入解释:

六头牛排成一排,高度依次是 10, 3, 7, 4, 12, 2。

Sample Output

5

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 乱发节的更多相关文章

  1. BZOJ1660: [Usaco2006 Nov]Bad Hair Day 乱发节(单调栈)

    题意 题目链接 Sol 单调栈板子题.. 找到向左第一个比他大的位置,然后判断一下就可以了 #include<bits/stdc++.h> //#define int long long ...

  2. BZOJ 1660: [Usaco2006 Nov]Bad Hair Day 乱发节( 单调栈 )

    维护一个h严格递减的栈 , 出栈时计算一下就好了.. ------------------------------------------------------------------------- ...

  3. 1660: [Usaco2006 Nov]Bad Hair Day 乱发节

    1660: [Usaco2006 Nov]Bad Hair Day 乱发节 Time Limit: 2 Sec  Memory Limit: 64 MB Submit: 665  Solved: 31 ...

  4. 【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 ...

  5. BZOJ 1660: [Usaco2006 Nov]Bad Hair Day 乱发节

    Description Input * Line 1: 牛的数量 N. * Lines 2..N+1: 第 i+1 是一个整数,表示第i头牛的高度. Output * Line 1: 一个整数表示c[ ...

  6. 【BZOJ】1660: [Usaco2006 Nov]Bad Hair Day 乱发节(单调栈)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1660 单调栈裸题..累计比每一个点高的个数即可. #include <cstdio> # ...

  7. BZOJ 1660 [Usaco2006 Nov]Bad Hair Day 乱发节:单调栈

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1660 题意: 有n头牛,身高分别为h[i]. 它们排成一排,面向右边.第i头牛可以看见在它 ...

  8. [Usaco2006 Nov]Bad Hair Day 乱发节

    Time Limit: 2 Sec  Memory Limit: 64 MBSubmit: 1268  Solved: 625[Submit][Status][Discuss] Description ...

  9. bzoj 1660: [Usaco2006 Nov]Bad Hair Day 乱发节【单调栈】

    开一个单调递减的单调栈,然后用sum数组维护每个点的答案,新加点的时候一边退栈一边把退掉的点的sum加进来 #include<iostream> #include<cstdio> ...

随机推荐

  1. 搜搜(www.soso.com),I 老虎油!

    搜搜(www.soso.com),I 老虎油! 太阳火神的漂亮人生 (http://blog.csdn.net/opengl_es) 本文遵循"署名-非商业用途-保持一致"创作公用 ...

  2. Linux中date命令的各种实用方法--转载

    在linux环境中,不管是编程还是其他维护,时间是必不可少的,也经常会用到时间的运算,自己也曾经为时间的各种表示方法和如何修改时间而困惑,熟练运用date命令来表示自己想要表示的时间,肯定可以给自己的 ...

  3. navicat导入mysql数据库sql时报错或数据不完全问题

    错误详情:[Err] [Imp] 2006 - MySQL server has gone away 或无提示错误,但是导入数据明显缺少字段和数据 找到服务器上的MYSQL安装目录下的my.ini文件 ...

  4. python瓦登尔湖词频统计

    #瓦登尔湖词频统计: import string path = 'D:/python3/Walden.txt' with open(path,'r',encoding= 'utf-8') as tex ...

  5. Centos6.3 配置yum 163源

    1. 下载repo文件    下载地址:http://mirrors.163.com/.help/CentOS6-Base-163.repo 2. 备份并替换系统的repo文件[root@localh ...

  6. Template Method 模板方法

      简介 定义一个操作中的算法的骨架,而将一些步骤延迟到子类中. 模板方法使得子类可以不改变一个算法的结构即可重定义该算法的某些特定步骤的细节 抽象模板AbstractClass的方法分为两类: 基本 ...

  7. PHP 网页爬虫

    只能爬一个页面 <?php function get_urls($url){ $url_array=array(); $the_first_content=file_get_contents($ ...

  8. Excel 2007中的新文件格式

    *.xlsx:基于XML文件格式的Excel 2007工作簿缺省格式 *.xlsm:基于XML且启用宏的Excel 2007工作簿 *.xltx:Excel2007模板格式 *.xltm:Excel ...

  9. (转)mysql 的 find_in_set函数使用方法

    举个例子来说: 有个文章表里面有个type字段,他存储的是文章类型,有 1头条,2推荐,3热点,4图文 .....11,12,13等等 现在有篇文章他既是 头条,又是热点,还是图文, type中以 1 ...

  10. 了解<hx>标签,为你的网页添加标题

    文章的段落用<p>标签,那么文章的标题用什么标签呢?在本节我们将使用<hx>标签来制作文章的标题.标题标签一共有6个,h1.h2.h3.h4.h5.h6分别为一级标题.二级标题 ...