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...

POJ 3250 Bad Hair Day

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

我是如何成为一名python大咖的?

人生苦短,都说必须python,那么我分享下我是如何从小白成为Python资深开发者的吧。2014年我大学刚毕业..

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 单调栈

POJ3250 Bad Hair Day 单调栈

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   ...

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

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

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

Bad Hair Day Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 17352   ...
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

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