POJ——T 3250 Bad Hair Day】的更多相关文章

http://poj.org/problem?id=3250 Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 19619   Accepted: 6702 Description 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 h…
1.Poj 3250  Bad Hair Day 2.链接:http://poj.org/problem?id=3250 3.总结:单调栈 题意:n头牛,当i>j,j在i的右边并且i与j之间的所有牛均比i矮,i就可看到j.i可看到的所有牛数记为ai,求S(ai),(1<=i<=n). 转化一下,求j可以被多少牛看到.这样就直接单调栈,求从j往前单调递增的数量. #include<iostream> #include<cstring> #include<cma…
http://poj.org/problem?id=3250 Bad Hair Day Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 11473   Accepted: 3871 Description Some of Farmer John's N cows (1 ≤ N ≤ 80,000) are having a bad hair day! Since each cow is self-conscious abou…
题目链接:http://poj.org/problem?id=3250 思路分析:题目要求求每头牛看见的牛的数量之和,即求每头牛被看见的次数和:现在要求如何求出每头牛被看见的次数? 考虑到对于某头特定的牛来说,看见它的牛一定在它的左边,另外其高度应该大于该牛的高度,所以只需要计算在其左边并高度大于它的牛的数目即可: 考虑构建一个栈,在某头牛入栈时,弹出栈中高度小于它的牛,剩下的牛高度大于它,此时计算栈的长度就可以得到该牛被看见的次数. 代码如下: #include<iostream> #inc…
http://poj.org/problem?id=3250 Bad Hair Day Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 15956   Accepted: 5391 Description Some of Farmer John's N cows (1 ≤ N ≤ 80,000) are having a bad hair day! Since each cow is self-conscious abou…
http://poj.org/problem?id=3250 Bad Hair Day Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 15985   Accepted: 5404 Description Some of Farmer John's N cows (1 ≤ N ≤ 80,000) are having a bad hair day! Since each cow is self-conscious abou…
[题目链接] http://poj.org/problem?id=3250 [题目大意] 有n头牛,每头牛都有一定的高度,他能看到在离他最近的比他高的牛前面的所有牛 现在每头牛往右看,问每头牛能看到的牛的数量的总和. [题解] 单调栈维护每个数字右边第一个比其大的数字的位置,从后往前计算, 为保证最后一段计算的正确性,在最后一个位置后面加一个无限高的哨兵即可. [代码] #include <cstdio> using namespace std; const int N=80010; type…
维护一个单调栈,保持从大到小的顺序,每次加入一个元素都将其推到尽可能栈底,知道碰到一个比他大的,然后res+=tail,说明这个cow的头可以被前面tail个cow看到.如果中间出现一个超级高的,自然会推到栈底,即此元素以前的cow看不到此元素后面cow的头,即res不会加此元素前面的个数,说明是正确的. 注意要用long long 或者 __int64类型. 刚开始看着80000不大的样子,其实最大情况下res有 1+2+....+80000 = 3200040000,超过int范围.以后还是…
#include<iostream> #include<cstring> #include<algorithm> #include<cstdio> #define Maxn 100010 using namespace std; __int64 ans=; int Stack[Maxn],top; int main() { int n,i,j,a; while(scanf("%d",&n)!=EOF) { ans=; top=;…
Bad Hair Day Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 15922   Accepted: 5374 Description 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…