poj3250

//(栈)poj3250将第i头牛能看到多少牛传化为第i头牛能被多少牛看见

/*

#include <stdio.h>
#include <stack>
using namespace std;
int main(){
	unsigned long N,ans=0;
	stack<unsigned long>s;
	scanf("%ld",&N);
	while(N--){
		unsigned long cowHigh;
		scanf("%ld",&cowHigh);
		while(!s.empty()&&s.top()<=cowHigh) s.pop();
		ans+=s.size();
		s.push(cowHigh);
	}
	printf("%ld",ans);
	return 0;
}

//*/

  

时间: 2024-12-14 09:53:03

poj3250的相关文章

POJ3250[USACO2006Nov]Bad Hair Day[单调栈]

Bad Hair Day Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 17774   Accepted: 6000 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

[poj3250]单调栈 Bad Hair Day

解题关键:将每头牛看到的牛头数总和转化为每头牛被看到的次数,然后用单调栈求解,其实做这道题的目的只是熟悉下单调栈 此题为递减栈 1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 #include<cstdlib> 5 #include<stack> 6 #include<iostream> 7 using namespace std; 8 typedef lo

POJ3250(单调栈)

Bad Hair Day Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 17614   Accepted: 5937 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

poj3250 Bad Hair Day

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 to count the number of other cows that can see the top of other cows' heads. Each cow i has a sp

机试练习02:poj3250——Bad Hair Day

参考来源:https://blog.csdn.net/htt_h/article/details/39716905 一.题解方法 维护一个单调递减队列,如果输入元素大于队尾元素,则清空队列.因此,队尾减队头就是所有矮于当前身高的奶牛数. 二.题解代码 1 #include <iostream> 2 3 using namespace std; 4 5 6 int que[80000]; 7 int head = 0, rear = -1; 8 9 int main() 10 { 11 int

DP总结 ——QPH

常见优化 单调队列 形式 dp[i]=min{f(k)} dp[i]=max{f(k)} 要求 f(k)是关于k的函数 k的范围和i有关 转移方法 维护一个单调递增(减)的队列,可以在两头弹出元素,一头压入元素. 队列中维护的是两个值.一个是位置,这和k的范围有关系,另外一个是f(k)的值,这个用来维护单调性,当然如果f(k)的值可以利用dp值在O(1)的时间内计算出来的话队列中可以只维护一个表示位置的变量. 枚举到一个i的时候,首先判断队首元素的位置是否已经不满足k的范围了,如果不满足就将队首

POJ3250---Bad Hair Day(单调栈)

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 to count the number of other cows that can see the top of other cows' heads. Each cow i has a sp

单调栈练习题题解

单调栈 单调栈顾名思义就是让栈中的元素是单调的,要么递增,要么递减.同样它也满足栈的性质,先进后出. 单调递增栈,则从栈顶到栈底的元素是严格递增的 单调递减栈,则从栈顶到栈底的元素是严格递减的 练习题 单调栈 练习题 POJ3250 POJ2796 BZOJ1113 HDU1506 POJ2559 JDFZ2997 POJ3250 POJ3250传送门 对于每一个牛来说,能看到的数目为向右数身高比它小的个数,累加就是答案. 所以可以倒着维护一个单调递增的栈,记录i之前的弹栈数目,累加. (正着也