POJ 3044单调栈】的更多相关文章

题意: 思路: 单调栈 // by SiriusRen #include <stack> #include <cstdio> using namespace std; stack<int>s; int n,w,ans=0,xx,yy; int main() { scanf("%d%d",&n,&w); for(int i=1;i<=n;i++) { scanf("%d%d",&xx,&yy);…
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…
题意:求柱状图中最大矩形面积. 单调栈:顾名思义就是栈内元素单调递增的栈. 每次插入数据来维护这个栈,假设当前须要插入的数据小于栈顶的元素,那就一直弹出栈顶的元素.直到满足当前须要插入的元素大于栈顶元素为止.能够easy求出某个数左边或右边,第一个大于或小于它的数,且复杂度是O(n). 思路:easy先想到一个好的枚举方式:以当前柱状为扩展点,往左边和右边扩展.当遇到一个比当前柱状小的柱状时停止扩展.以当前柱状的高度为矩形的高.向左右扩展的距离之差为矩形的长度,这样对n个柱状进行扫描之后可得最大…
题目链接:http://poj.org/problem?id=2796 单调栈可以O(n)得到以每个位置为最小值,向左右最多扩展到哪里. #include<cstdio> #include<algorithm> #include<stack> using namespace std; ; int a[maxn]; int l[maxn]; int r[maxn]; long long pre[maxn]; stack< pair<int,int> &g…
1619 - Feel Good Time limit: 3.000 seconds   Bill is developing a new mathematical theory for human emotions. His recent investigations are dedi- cated to studying how good or bad days in uent people's memories about some period of life. A new idea B…
和poj2082差不多,加了一个宽度的条件 #include<iostream> #include<string> #include<cmath> #include<cstdio> #include<algorithm> #define max(a,b) (a>b?a:b) #define abs(a) ((a)>0?(a):-(a)) #define min(a,b) (a<b?a:b) using namespace std…
给出一系列的1*h的矩形,求矩形的最大面积. 如图: 题解链接:点我 #include <iostream> #include <cstdio> using namespace std; ; struct Elem { int height; int count; }; Elem stack[N]; int top; int main() { int height, n; long long ans, tot, tmp; while (scanf("%d", &…
和poj2082差不多,加了一个宽度的条件 #include<cstdio> #include<cmath> #include<algorithm> #include<cstring> #include<iostream> using namespace std; ; pair<int,int> ele[MAXN]; int main(){ int height, n; int w; int i,j,k,h; int ans, tot…
http://poj.org/problem?id=3415 Common Substrings Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 5805   Accepted: 1911 Description A substring of a string T is defined as: T(i, k)=TiTi+1...Ti+k-1, 1≤i≤i+k-1≤|T|. Given two strings A, B an…
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…