poj 3250 Bad Hair Day

原创 2012年03月27日 00:51:26

//单调栈。。。

#include <iostream>

#include <stack>
#include <cstdio>
using namespace std;
stack<long long> p;
int main()
{
    long long n;
    long long num;
    while(cin >> n)
    {
        long long sum = 0;
        cin >> num;
        p.push(num);
        for(int i = 2; i <= n; i++)
        {
            cin >> num;
            while( !p.empty() && p.top() <= num)   //注意等号啊
            {
                p.pop();
            }
            sum += p.size();
            p.push(num);
        }
        printf("%I64d\n",sum);
        while( !p.empty() )
            p.pop();
    }
    return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

Bad Hair Day POJ - 3250

题目链接:点我 Some of Farmer John's N cows (1 ≤ N ≤ 80,000) are having a bad hair day! Since each cow i...
  • cccruel
  • cccruel
  • 2017年07月22日 09:45
  • 54

poj3250 Bad Hair Day

Description Some of Farmer John's N cows (1 ≤ N ≤ 80,000) are having a bad hair day! Since each cow...

poj3250Bad Hair Day【单调栈】

Language: Default Bad Hair Day Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 1...

POJ 3250 Bad Hair Day

顺手写个单调队列。。。。 Bad Hair Day Time Limit: 2000MS   Memory Limit: 65536KB   64b...

POJ3250---Bad Hair Day(单调栈)

DescriptionSome of Farmer John’s N cows (1 ≤ N ≤ 80,000) are having a bad hair day! Since each cow i...

POJ 3250 Bad Hair Day 【单调栈】

Bad Hair Day Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 15952   ...
  • wyjwyl
  • wyjwyl
  • 2015年11月15日 18:22
  • 299

ACM--单调栈--Bad Hair Day--POJ--3250--水

POJ地址:http://poj.org/problem?id=3250 Bad Hair Day Description Some of Farmer John's N cows (...

POj 3250 Bad Hair Day (思维+单调栈)

Bad Hair Day Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 19167 Accepted: 6522 De...
  • nka_kun
  • nka_kun
  • 2017年07月18日 12:50
  • 125

POJ3250——Bad Hair Day(栈的应用)

Bad Hair Day Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 17352   ...

POJ3250 Bad Hair Day 单调栈

Bad Hair Day Some of Farmer John's N cows (1 ≤ N ≤ 80,000) are having a bad hair day! Since each co...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:poj 3250 Bad Hair Day
举报原因:
原因补充:

(最多只允许输入30个字)