随笔分类 - 【单调栈】
【POJ】3494 Largest Submatrix of All 1’s
摘要:1 #include<cstdio> 2 #include<algorithm> 3 #define MAXN 2010 4 using namespace std; 5 int a[MAXN][MAXN]; 6 struct node 7 { 8 int w,h; 9 }st[MAXN];10 int main()11 {12 node temp;13 int n,m,i,j,ans,top,wide;14 while(~scanf("%d%d",&n,&m))15 {16 for(i=0;i<n;i++)17 {18...
阅读全文
【POJ】3250 Bad Hair Day
摘要:1 #include<cstdio> 2 typedef __int64 LL; 3 #define MAXN 80010 4 int st[MAXN]; 5 int main() 6 { 7 LL ans; 8 int n,i,x,top; 9 while(~scanf("%d",&n))10 {11 for(top=-1,ans=i=0;i<n;i++)12 {13 scanf("%d",&x);14 for(;top>-1&&st[top]<=x;top--);15 ...
阅读全文
【POJ】2796 Feel Good
摘要:1 #include<cstdio> 2 #define MAXN 100010 3 typedef __int64 LL; 4 struct node 5 { 6 LL w,h; 7 int x,y; 8 }; 9 node st[MAXN];10 int main()11 {12 node temp;13 LL ans,wide;14 int n,i,top,x,y,R;15 while(~scanf("%d",&n))16 {17 ans=top=-1;18 for(i=0;i<n;i++)19 ...
阅读全文
【SPOJ】11578 A Famous City
摘要:1 #include<cstdio> 2 #define MAXN 100010 3 int st[MAXN]; 4 int main() 5 { 6 bool flag; 7 int n,i,x,top,ans,ca=1; 8 while(~scanf("%d",&n)) 9 {10 for(top=-1,ans=i=0;i<n;i++)11 {12 flag=true;13 scanf("%d",&x);14 for(;top>-1&&st[top]>=...
阅读全文
【POJ】2559 Largest Rectangle in a Histogram
摘要:1 #include<cstdio> 2 #include<algorithm> 3 typedef __int64 LL; 4 #define MAXN 100010 5 using namespace std; 6 struct node 7 { 8 LL w,h; 9 };10 node st[MAXN];11 int main()12 {13 LL ans,wide;14 node temp;15 int n,i,top;16 while(scanf("%d",&n),n)17 {18 for(top=-1,ans=i=...
阅读全文
【POJ】2082 Terrible Sets
摘要:1 #include<cstdio> 2 #include<algorithm> 3 #define MAXN 50010 4 using namespace std; 5 struct node 6 { 7 int w,h; 8 }st[MAXN]; 9 int main()10 {11 node temp;12 int i,j,n,ans,top,wide;13 while(scanf("%d",&n),n!=-1)14 {15 top=-1;16 for(ans=i=0;i<n;i++)17 {18...
阅读全文
浙公网安备 33010602011771号