poj 3250 单调栈 *
2015-07-23 16:28
267 查看
题意:一群高度不完全相同的牛从左到右站成一排,每头牛只能看见它右边的比它矮的牛的发型,若遇到一头高度大于或等于它的牛,则无法继续看到这头牛后面的其他牛。
给出这些牛的高度,要求每头牛可以看到的牛的数量的和。
给出这些牛的高度,要求每头牛可以看到的牛的数量的和。
#include<cstdio> #include<iostream> #include<algorithm> #include<cstring> #include<cmath> #include<queue> #include<map> #include<stack> using namespace std; #define MOD 1000000007 const int INF=0x3f3f3f3f; const double eps=1e-5; typedef long long ll; #define cl(a) memset(a,0,sizeof(a)) #define ts printf("*****\n"); const int MAXN=80005; int n,m,tt; int st[MAXN]; int main() { int i,j,k; #ifndef ONLINE_JUDGE freopen("1.in","r",stdin); #endif while(~scanf("%d",&n)) { int top=0; ll sum=0; for(i=0;i<n;i++) { int a; scanf("%d",&a); while(top>0&&st[top-1]<=a) top--; sum+=top; st[top++]=a; } printf("%lld\n",sum); } }
相关文章推荐
- 暑假集训第二周——贪心 N - The King 国王
- web.xml标签(元素)出现顺序
- JavaScript中你所不知道的Object(一)
- Linux下同步工具inotify+rsync使用详解
- hdu5285 二分图的判定
- N皇后问题(HDU 2553)
- ViewPager 详解(五)-----使用Fragment实现ViewPager滑动
- 【IAP支付之二】In app purchase 本地购买和服务器购买两种购买模式
- Unity3D动画贴图、滚动纹理、滚动贴图脚本
- 激活2003终端服务
- Coursera台大机器学习技法课程笔记05-Kernel Logistic Regression
- Java的Package与Import机制--心得
- DataTables-table的布局sDom
- 认知诊断模型
- 函数栈详解以及堆区与栈区的区别
- Android开发:setAlpha()方法和常用RGB颜色表----颜色, r g b分量数值(int), 16进制表示 一一对应
- Android Studio运行安卓程序报Failure [INSTALL_FAILED_OLDER_SDK]的解决办法
- 分割线的写法
- Android UI
- Android studio之启动AVD模拟器异常