[WOJ1583]向右看齐】的更多相关文章

题目链接: WOJ1583 题目分析: 大水题--我就来水个题解 倒序扫,单调栈维护单减序列,每个对象的答案是栈里它下面那个元素 代码: #include<bits/stdc++.h> #define MAXN (1000000+5) using namespace std; inline int read(){ int cnt=0,f=1;char c; c=getchar(); while(!isdigit(c)){ if(c=='-')f=-f; c=getchar(); } while…
单调栈真的很好用呢! P2947 [USACO09MAR]向右看齐Look Up 题目描述 Farmer John's N (1 <= N <= 100,000) cows, conveniently numbered 1..N, are once again standing in a row. Cow i has height H_i (1 <= H_i <= 1,000,000). Each cow is looking to her left toward those wi…
题目描述 Farmer John's N (1 <= N <= 100,000) cows, conveniently numbered 1..N, are once again standing in a row. Cow i has height H_i (1 <= H_i <= 1,000,000). Each cow is looking to her left toward those with higher index numbers. We say that cow…
向右看齐 题目链接 此题可用单调栈O(n)求解 维护一个单调递减栈,元素从左到右入栈 若新加元素大于栈中元素,则栈中元素的仰望对象即为新加元素 每次将小于新加元素的栈中元素弹出,记录下答案 #include<iostream> #include<cstdio> using namespace std; #define N 100010 int n,w[N],stack[N],top,ans[N]; int main() { scanf("%d",&n);…
题目描述 N 头奶牛被紧急动员起来了,它们排成了一条长列.从左向右看,排在第 i 个位置的奶牛身高为 Hi.约翰一声令下,所有奶牛向右看齐.假设每头奶牛只能看到比自己高的牛.请问它们各自看到的最近的一头奶牛分别是谁呢?Input 第一行:单个整数 N,1≤N≤106 第二行到 N+1 行:第 i+1 行有一个整数 Hi,1≤Hi≤106Output 第一行到第 N 行:第 i 行有一个整数 Ci,表示第 i 头奶牛向右看到的最近的一头奶牛编号,如果看不到任何奶牛,Ci 为 0. 一开始用朴素的循…
题目描述 Farmer John's N (1 <= N <= 100,000) cows, conveniently numbered 1..N, are once again standing in a row. Cow i has height H_i (1 <= H_i <= 1,000,000). Each cow is looking to her left toward those with higher index numbers. We say that cow…
https://www.luogu.org/problem/P2947 题目描述 Farmer John's N (1 <= N <= 100,000) cows, conveniently numbered 1..N, are once again standing in a row. Cow i has height Hi (1 <= Hi <= 1,000,000). Each cow is looking to her left toward those with high…
题目链接:https://www.luogu.org/problemnew/show/P2947 因为在单调队列上被dalao们锤爆 怒刷单调队列题 何为单调队列? 设我们的队列为从左至右单调递增 对于样例数据 3 2 6 1 1 2 我们先把3入队 此时队列:3 再将2从后面入队 此时队列:2 3 再将6从后面入队 但是,为了满足队列从左至右的单调性,我们将2,3出队 此时队列:6 再将1从后面入队 此时队列:1 6 再将1从后面入队 此时队列:1 1 6 再将2从后面入队 但是,为了满足队列…
目录 题目 思路 \(Code\) 题目 戳 思路 单调栈裸题 \(Code\) #include<stack> #include<cstdio> #include<string> #include<cstring> #include<iostream> #define MAXN 100001 #define rr register using namespace std; int n,ans[MAXN]; struct mu{ int num,…
#include<cstdio> #include<algorithm> #include<stack> #include<cctype> using namespace std; struct cow{ int id; int data; cow(,):id(id),data(data){ } }ans[]; stack<cow> q; int n,tmp,cnt; inline bool cmp(const cow &a,const…