FZU 1845 Look Up(单调栈)
来源:互联网 发布:收费站车流量数据分析 编辑:程序博客网 时间:2024/04/30 04:23
Description
N (1 <= N <= 100,000) monkeys in the mountains, conveniently numbered 1..N, are once again standing in a row. Monkey i has height Hi (1 <= Hi <= 1,000,000).
Each monkey is looking to his left toward those with higher index numbers. We say that monkey i "looks up" to monkey j if i < j and Hi < Hj. For each monkey i, we would like to know the index of the first monkey in line looked up to by monkey i.
Input
Input consists of several testcases. The format of each case as follow:
Output
For each testcase, output N lines. Line i contains a single integer representing the smallest index of a monkey up to which monkey i looks. If no such monkey exists, print 0.
Sample Input
Sample Output
题意:问你一个猴子向左看最远能看多远。
分析:搞一个单调递增栈就行了。
#include<cstdio>#include<cstring>#include<algorithm>#include<vector>#include<string>#include<iostream>#include<queue>#include<cmath>#include<map>#include<stack>#include<set>using namespace std;#define REPF( i , a , b ) for ( int i = a ; i <= b ; ++ i )#define REP( i , n ) for ( int i = 0 ; i < n ; ++ i )#define CLEAR( a , x ) memset ( a , x , sizeof a )const int INF=0x3f3f3f3f;typedef long long LL;const int maxn=1e5+100;int s[maxn],p[maxn];int a[maxn],n,R[maxn];int main(){ while(~scanf("%d",&n)) { REPF(i,1,n) scanf("%d",&a[i]); int top=0; for(int i=n;i>=1;i--) { while(top>0&&a[i]>=a[s[top]]) --top; R[i]=s[top]; s[++top]=i; } for(int i=1;i<=n;i++) printf("%d\n",R[i]); }}
- FZU 1845 Look Up(单调栈)
- bzoj3401 Look up(单调栈)
- [BZOJ3401][Usaco2009 Mar]Look Up 仰望(单调栈)
- 洛谷 2947 仰望Look Up(单调栈)
- 【BZOJ3401】[Usaco2009 Mar]Look Up 仰望【单调栈】
- bzoj3401 [Usaco2009 Mar]Look Up 仰望 单调栈
- 【BZOJ3401】【单调栈】[Usaco2009 Mar]Look Up 仰望 题解
- FOJ 1845 Look Up
- FZU 2190 非提的救赎(单调栈)
- Fzu-2190 非提的救赎 (单调栈)
- LDAP Look up
- dns look up command
- DTC look up 例子
- 低头族,Look Up!
- FZU 2163 多米诺骨牌(单调栈)
- 【单调栈】fzu 2136取糖果
- fzu 1894 志愿者选拔(单调队列)
- FZU 1894 志愿者选拔 (单调队列)
- [linux]如何安装.bin类型的文件
- 代理模式,JDK动态代理
- C# 类型基础
- PHP面试题遇到的几个坑。...面壁ing
- FPGA中modelsim对IP的仿真
- FZU 1845 Look Up(单调栈)
- 多线程---有四个线程1、2、3、4。线程1的功能就是输出1,线程2的功能就是输出2,以此类推.........现在有四个文件ABCD
- 在django template中设置临时变量
- C# 中的枚举器
- c++读书笔记——类的定义
- git ---- Tortoise git -----ppk ---rsa
- 控制浏览器定时刷新、缓存、重定向
- C# 理解泛型
- NYOJ 网络覆盖+数学问题+ceil的使用