poj 3250 Bad Hair Day(单调栈)
来源:互联网 发布:数据可视化的产品目标 编辑:程序博客网 时间:2024/06/05 05:18
一排牛站着向右看,长的高的牛可以看到长的矮的牛的头顶,每个牛都可以看到0至多个牛的头顶,把每个牛能看到的加起来。单调栈水题
#include <stdio.h>#include <string.h>#include <algorithm>#include <stack>using namespace std;typedef long long LL;const int MAXN = 80010;LL num[MAXN];int index[MAXN];int main(){ int n; scanf("%d",&n); for(int i = 0; i < n; ++i) scanf("%I64d",&num[i]); stack<int> s; for(int i = n-1; i >= 0; --i) { while(s.size() && num[s.top()] < num[i]) s.pop(); if(s.size()) index[i] = s.top(); else index[i] = n; s.push(i); } LL res = 0; for(int i = 0; i < n; ++i) res += (index[i]-i-1); printf("%I64d\n",res); return 0;}
阅读全文
0 0
- poj 3250:Bad Hair Day---单调栈
- POJ 3250 Bad Hair Day(单调栈)
- POJ 3250 Bad Hair Day(单调栈)
- POJ 3250 Bad Hair Day 单调栈
- poj 3250 Bad Hair Day 单调栈
- [单调栈] poj 3250 Bad Hair Day
- POJ 3250 Bad Hair Day 【单调栈】
- poj 3250 Bad Hair Day 【单调栈】
- poj 3250 Bad Hair Day(单调栈)
- Poj 3250 Bad Hair Day 【单调栈】
- POJ 3250 - Bad hair day(单调栈)
- poj-3250 Bad Hair Day(单调栈)
- Bad Hair Day(POJ 3250) 单调栈
- poj 3250 Bad Hair Day单调栈
- Bad Hair Day -- 3250poj 单调栈
- POJ 3250 Bad Hair Day (单调栈)
- poj 3250 Bad Hair Day(单调栈)
- POJ 3250 Bad Hair Day【单调栈】
- android.os.FileUriExposedException
- getter,setter都要重写
- 业余草推荐阿里妈妈自研广告点击率预估核心算法MLR
- Android和IOS js和原生调用的注入的js代码
- MQC功能测试大揭秘(1)
- poj 3250 Bad Hair Day(单调栈)
- c标签 if else c标签 总结
- MYSQL数据库将 表1的字段值更改为表2字段的值
- [BZOJ2815][ZJOI2012]灾难(倍增lca+top)
- 【git】将代码放到远程仓库
- linux双向链表List结构分析
- [Usaco2014 Mar]Sabotage(dp)
- 设计模式原则----里氏替换原则,依赖倒置原则
- 关于mysql中LOAD DATA LOCAL INFILE指定列