博客
关于我
poj 3250 Bad Hair Day 栈的简单运用
阅读量:697 次
发布时间:2019-03-17

本文共 597 字,大约阅读时间需要 1 分钟。

#include 
#include
using namespace std;int main(){ stack
s; int n; while (cin >> n) { int a[100000]; for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); if (!s.empty() && a[i] < s.top()) { s.pop(); num--; } sum += num; num++; s.push(a[i]); } while (!s.empty()) s.pop(); cout << sum << endl; }}

注:请注意上述代码已剥离除<div><pre>等HTML标签外的所有无关内容,仅保留原始代码核心逻辑。代码已经过轻微优化,调整部分注释和格式,使其更易读。上述代码功能与原文一致。

转载地址:http://btnez.baihongyu.com/

你可能感兴趣的文章
poj1936 假期计划第一水
查看>>
poj1958-汉诺四塔问题(三种方法)
查看>>
poj1988(并查集)
查看>>
POJ2007+几何+极角排序
查看>>
poj2039
查看>>
poj2135(简单的最小费用流问题)
查看>>
poj2195 bfs+最小权匹配
查看>>
POJ2251
查看>>
POJ2253-Frogger
查看>>
poj2309
查看>>
POJ2390 Bank Interest【水题】
查看>>
poj2398
查看>>
poj2478欧拉函数
查看>>
poj2546
查看>>
POJ2728 Desert King
查看>>
POJ2794 Double Patience[离散概率 状压DP]
查看>>
poj2828(线段树查找序列第k小的值)
查看>>
POJ2891:Strange Way to Express Integers——题解
查看>>
poj3045 Cow Acrobats(二分最大化最小值)
查看>>
poj3061 Subsequence(尺取法)
查看>>