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;
}

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

查看所有标签

猜你喜欢:

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

Essential PHP Security

Essential PHP Security

Chris Shiflett / O'Reilly Media / 2005-10-13 / USD 29.95

Being highly flexible in building dynamic, database-driven web applications makes the PHP programming language one of the most popular web development tools in use today. It also works beautifully wit......一起来看看 《Essential PHP Security》 这本书的介绍吧!

随机密码生成器
随机密码生成器

多种字符组合密码

MD5 加密
MD5 加密

MD5 加密工具

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具