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. 缓冲运动-1-[解决1].html

    <!DOCTYPE html> <html> <head lang="en">     <meta charset="UTF-8 ...

  2. winserver2008下创建计划任务注意点

    winserver2008下创建任务计划注意点: 1.建立独立用户,可以给其赋予administrator权限 2.起始于(可选):要填写exe文件所在路径 3.设置成“不管用户是否登录都运行”,同时 ...

  3. [转] restrict关键字用法

    PS: 在函数中,指针参数指定了restrict,表示这个指针指向的这段区域只能通过这个指针修改 c99中新增加了一个类型定义,就是restrict. 看了下网上的相关贴子,但还是问题解决的不够.下面 ...

  4. Day2 - Python基础2 列表、字典、集合

    Python之路,Day2 - Python基础2   本节内容 列表.元组操作 字符串操作 字典操作 集合操作 文件操作 字符编码与转码 1. 列表.元组操作 列表是我们最以后最常用的数据类型之一, ...

  5. ProgressBar 基本介绍

    简介 ProgressBar 继承自View,用于在界面上显示一个进度指示的界面. 1.ProgressBar有两个进度,一个是android:progress,另一个是android:seconda ...

  6. 用CSS创建小三角形问题(笔试题常考)

    笔试题中经常遇到用CSS实现某个Div边框添加三角形问题,掌握一点,合理利用div的边框,当div有宽有高时,边框就是不起眼的边框,当div的宽高为0时,边框就是一个小方块,把剩下的三个边透明就是神奇 ...

  7. 【转】 Xcode基本操作

    原文: http://blog.csdn.net/phunxm/article/details/17044337 1.IDE概览 Gutter & Ribbon 焦点列:灰色深度与代码嵌套深度 ...

  8. AutoLayout适配

    http://www.raywenderlich.com/113768/adaptive-layout-tutorial-in-ios-9-getting-started iOS布局和屏幕适配的一点总 ...

  9. CompareValidator ASP控件

    定义和用法 CompareValidator 控件用于将由用户输入到输入控件的值与输入到其他输入控件的值或常数值进行比较. 注释:如果输入控件为空,则不会调用任何验证函数,并且验证将成功.使用 Req ...

  10. interrupt & storage & DMA

    1.Interrupt: The occurrence of an event is usually signaled by aninterrupt from either the hardware ...