Bzoj 1660: [usaco Nov] bad hair day hair Festival

Source: Internet
Author: User
Description

Input

* Line 1: Number of cattle n.

* Lines 2. n + 1: The I + 1 is an integer that indicates the height of the I head ox. Output

* Line 1: an integer that represents the sum of C [1] to C [N.

Question:

The bzoj server seems to be faulty, and the picture is not displayed properly. Just look at the above picture.

Set Niu I to see the farthest position: see [I].

Scan from the front to the back and find the see value. Set a bull a in front and B in the back. If H [B]> = H [a], then the ox A will never be the ox's see value.

We can maintain this monotonicity with a monotonous stack,

When the stack top bull height is less than the current bull height, the stack top bull height> = Current bull height, then this stack top bull is the current bull's see value, import the current bull into the stack.

Ans = sigma (see [I]-i-1 ).

Code:

#include<cstdio>#include<cstring>#include<algorithm>//by zrt//problem:using namespace std;const int MAXN=80005;struct N{    int x,w;    N(int a=0,int b=0){        x=a,w=b;    }};N stk[MAXN];int top;int see[MAXN];int n;int h[MAXN];int inf=1<<30;typedef long long LL;int main(){    #ifdef LOCAL    freopen("in.txt","r",stdin);    freopen("out.txt","w",stdout);    #endif    scanf("%d",&n);    for(int i=1;i<=n;i++){        scanf("%d",&h[i]);    }    stk[top++]=N(n+1,inf);    for(int i=n;i>=1;i--){        while(stk[top-1].w

Bzoj 1660: [usaco Nov] bad hair day hair Festival

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.