POJ 3250 Bad Hair Day

栏目: 编程工具 · 发布时间: 7年前

内容简介:题目链接:分析:单调栈入门。依次向前模拟,直到找到比自己高的。

题目链接: http://poj.org/problem?id=3250

分析:单调栈入门。

依次向前模拟,直到找到比自己高的。

因为维护的是单调栈,那么就会保证之前的都能看到自己,统计答案,把该数放进栈中即可。

#include <cstdio>
#include <cstring>
#include <cctype>
#include <iostream>
#include <stack>
typedef long long ll;
static const int MAXN=100050;
using namespace std;
ll n,x,num,ans,s[MAXN];
inline void solve(ll x)
{
    while(s[num]<=x&&num) num--;
    ans+=num;
    s[++num]=x;
}
int main()
{
    scanf("%lld",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&x);
        solve(x);
    }
    printf("%lld\n",ans);
    return 0;
}

以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

The Art of UNIX Programming

The Art of UNIX Programming

Eric S. Raymond / Addison-Wesley / 2003-10-3 / USD 54.99

Writing better software: 30 years of UNIX development wisdom In this book, five years in the making, the author encapsulates three decades of unwritten, hard-won software engineering wisdom. Raymond b......一起来看看 《The Art of UNIX Programming》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试

HEX HSV 转换工具
HEX HSV 转换工具

HEX HSV 互换工具