POJ-3250-Bad Hair Day- 又是一颗单调栈
来源:互联网 发布:linux 改变文件夹权限 编辑:程序博客网 时间:2024/06/06 00:55
题意:n个牛排成一列向右看,牛i能看到牛j的头顶,当且仅当牛j在牛i的右边并且牛i与牛j之间的所有牛均比牛i矮。
设牛i能看到的牛数为Ci,求∑Ci
还是用单调栈秒掉就好了
#include <cstdio>#include <cmath>#include <cstring>#include <string>#include <algorithm>#include <iostream>#include <queue>#include <map>#include <set>#include <vector>using namespace std;__int64 max (__int64 a,__int64 b){return a<b?b:a;}struct node{__int64 l;__int64 r;__int64 h;};const int maxn=80005;node tm[maxn];__int64 top;__int64 ans=-1;void insert(node tt){while(top&& tm[top].h<=tt.h){tm[top-1].r=tm[top].r;node t=tm[top];ans+=t.r-t.l;top--;} tm[++top]=tt;}int main(){ __int64 n,i;scanf("%I64d",&n); ans=top=0;node tt;for (i=1;i<=n;i++){scanf("%I64d",&tt.h);tt.l=tt.r=i;insert(tt);}while(top){tm[top-1].r=tm[top].r; node t=tm[top]; ans+=t.r-t.l;top--;}printf("%I64d\n",ans);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(单调栈)
- 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(单调栈)
- JavaScript调试
- 二进制文件与文本文件区别
- hdu3622 2-SAT+二分
- Gym 100641 H Time Warp || 追击问题
- JavaScript语法
- POJ-3250-Bad Hair Day- 又是一颗单调栈
- HDU - 4271(经典字符串dp改)
- 自定义 CheckBox样式
- 窗口中的对象和元素
- shwoModalDialog弹出窗的属性
- Spring+Axis1.4开发WebService实例
- java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener
- 内置对象 DOM BOM
- CvMat、Mat、IplImage之间的转换