zoukankan      html  css  js  c++  java
  • 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

    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

    题解:
    单调栈水过。。。
    代码:
     1 #include<cstdio>
     2 #include<cstdlib>
     3 #include<cmath>
     4 #include<cstring>
     5 #include<algorithm>
     6 #include<iostream>
     7 #include<vector>
     8 #include<map>
     9 #include<set>
    10 #include<queue>
    11 #include<string>
    12 #define inf 1000000000
    13 #define maxn 80000+100
    14 #define maxm 500+100
    15 #define eps 1e-10
    16 #define ll long long
    17 #define pa pair<int,int>
    18 using namespace std;
    19 inline int read()
    20 {
    21     int x=0,f=1;char ch=getchar();
    22     while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    23     while(ch>='0'&&ch<='9'){x=10*x+ch-'0';ch=getchar();}
    24     return x*f;
    25 }
    26 int main()
    27 {
    28     freopen("input.txt","r",stdin);
    29     freopen("output.txt","w",stdout);
    30     int n=read(),a[maxn],sta[maxn];
    31     for(int i=1;i<=n;i++)a[i]=read();
    32     a[n+1]=inf;
    33     int top=0;
    34     ll ans=0;
    35     for(int i=1;i<=n+1;i++)
    36     {
    37         while(top>0&&a[i]>=a[sta[top]])ans+=i-sta[top--]-1;
    38         sta[++top]=i;
    39     }
    40     printf("%lld
    ",ans);
    41     return 0;
    42 }
    View Code
  • 相关阅读:
    C#获取htmltry
    分页存储过程的写法 可以被调用
    验证邮箱地址是否正确的方法
    WinForm 异步调用方法
    C#基础复习第一部
    PowerDesigner12.5 下载、汉化及破解
    C# Timer用法及实例详解
    ADO.NET复习笔记
    C# 使用委托实现多线程调用窗体
    C#中存储过程的调用
  • 原文地址:https://www.cnblogs.com/zyfzyf/p/3942297.html
Copyright © 2011-2022 走看看