Stack No.2 peaks problem

Source: Internet
Author: User

Haha think of summer vacation in the United States the first topic worth remembering!!

1#include <cstdio>2#include <cstring>3#include <iostream>4#include <stack>5 using namespacestd;6 intn,h[15010],n;//N is the number of elements in the stack n is a total of how many mountains7stack<int> s;//Build a stack8 intans;9 Ten intMain () One { Ascanf"%d",&N); -  for(intI=1; i<=n;i++) - { thescanf"%d",&h[i]); -Ans+=n;//reach the next peak plus the elements from the previous stack -  while(N&&h[i]>s.top ())//when the current mountain height is higher than the previous mountain height out of the stack -    { + S.pop (); -n--; +    } AS.push (H[i]);//put the current height into the stack atn++; - } -printf"%d", ans); - return 0; -}

Stack No.2 peaks problem

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.