【洛谷P2866】Bad Hair Day】的更多相关文章

P2866 [USACO06NOV]糟糕的一天Bad Hair Day 75通过 153提交 题目提供者洛谷OnlineJudge 标签USACO2006云端 难度普及/提高- 时空限制1s / 128MB 提交  讨论  题解 最新讨论更多讨论 题目标题 题目描述 Some of Farmer John's N cows (1 ≤ N ≤ 80,000) are having a bad hair day! Since each cow is self-conscious about her…
单调栈版子 #include<cstdio> #include<cstring> using namespace std; ; ,zh[N]; int read(){ ; char ch=getchar(); ') ch=getchar(); '){ sum=sum*+ch-'; ch=getchar(); } return sum; } int main(){ ; scanf("%d",&n); ;i<=n;i++){ a=read(); whi…
题目描述 Some of Farmer John's N cows (1 ≤ N ≤ 80,000) are having a bad hair day! Since each cow is self-conscious about her messy hairstyle, FJ wants to count the number of other cows that can see the top of other cows' heads. Each cow i has a specified…
题目描述 Some of Farmer John's N cows (1 ≤ N ≤ 80,000) are having a bad hair day! Since each cow is self-conscious about her messy hairstyle, FJ wants to count the number of other cows that can see the top of other cows' heads. Each cow i has a specified…
https://www.luogu.org/problem/show?pid=2866 题目描述 Some of Farmer John's N cows (1 ≤ N ≤ 80,000) are having a bad hair day! Since each cow is self-conscious about her messy hairstyle, FJ wants to count the number of other cows that can see the top of o…
链接:https://ac.nowcoder.com/acm/contest/984/A 来源:牛客网 题目描述 Some of Farmer John's N cows (1 ≤ N ≤ 80,000) are having a bad hair day! Since each cow is self-conscious about her messy hairstyle, FJ wants to count the number of other cows that can see the…
传送门 这是一道典型的单调栈. 题意理解 先来理解一下题意(原文翻译得有点问题). 其实就是求对于序列中的每一个数i,求出i到它右边第一个大于i的数之间的数字个数c[i].最后求出和. 首先可以暴力求解,时间复杂度o(n^2)显然TLE. 然后就是用单调栈来做. 单调栈 单调栈就是维护一个栈,使得栈中的元素是单调的(递增/递减). 假设是递减——对于每一个新来的元素,把栈顶大于这个元素的每一个数字全部弹出,最后把这个元素加进去. (如果栈为空,直接加入) 单调栈有什么用呢? 单调递增栈能以o(n…
看到这道题很容易想到单调栈,但我一开始想的是从后往前扫,但发现会有问题(因为这样会对后面牛的答案造成影响),所以这时我们要及时换一个思路,从前往后扫. 维护一个单调递减的栈,插入h[i]时,小等于它的数都要出栈,累加栈中元素数量,表示的意义就是:当前栈中的牛都是可以看到i这头牛的,即他们不会被i这头牛挡住. 1 #include<bits/stdc++.h> 2 using namespace std; 3 long long ans,h[80010]; 4 int s[80010],top,…
bzoj炸了,靠离线版题目做了两道(过过样例什么的还是轻松的)但是交不了,正巧洛谷有个"大牛分站",就转回洛谷做题了 水题先行,一道傻逼匈牙利 其实本来的思路是搜索然后发现写出来类似于匈牙利(⊙o⊙) (匈牙利的复杂度惊人,1e6秒过) #include <cstdio> ]; ],fir[],to[],nex[]; int N,n,p,q; void add(int p,int q) { nex[++N]=fir[p];to[N]=q;fir[p]=N; } bool f…
没有上司的舞会  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 钻石 Diamond       题目描述 Description Ural大学有N个职员,编号为1~N.他们有从属关系,也就是说他们的关系就像一棵以校长为根的树,父结点就是子结点的直接上司.每个职员有一个快乐指数.现在有个周年庆宴会,要求与会职员的快乐指数最大.但是,没有职员愿和直接上司一起与会. 输入描述 Input Description 第一行一个整数N.(1<=N<=6000)接下来N行,第i+1…