关于矩形的单调栈处理,这是这类题目第三次见到了,每次都只是少许变化。
wa了很多发,模拟的时候还是应该尽量小心。
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<stack>
#include<vector>
#include<queue>
#include<set>
#include<map>
//#include<regex>
#include<cstdio>
#define up(i,a,b) for(int i=a;i<b;i++)
#define dw(i,a,b) for(int i=a;i>b;i--)
#define upd(i,a,b) for(int i=a;i<=b;i++)
#define dwd(i,a,b) for(int i=a;i>=b;i--)
//#define local
typedef long long ll;
const double esp = 1e-6;
const double pi = acos(-1.0);
const int INF = 0x3f3f3f3f;
const int inf = 1e9;
using namespace std;
int read()
{char ch = getchar(); int x = 0, f = 1;while (ch<'0' || ch>'9') { if (ch == '-')f = -1; ch = getchar(); }while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }return x * f;
}
typedef pair<int, int> pir;
const int N = 3e3 + 10;
char grp[N][N];
int hi[N];
int n, m,ans;
int main()
{n = read(), m = read();up(i,0,n)scanf("%s", grp[i]);up(i, 0, n){int x=-1;int vec[N];up(j, 0, m){if (grp[i][j] == '1')hi[j] = hi[j] + 1;else hi[j] = 0; vec[j] = hi[j];}stack< pir > st;vec[m] = 0;upd(j, 0, m){int temp = j;if (st.empty() || p().first] < vec[j]){st.push(make_pair(j, temp));}while (!st.empty() && p().first] > vec[j]){if (st.top().second <= x){ans++; }temp = st.top().second;st.pop();}if (grp[i + 1][j] != '1')x = j;if (hi[j]) {if (st.empty())st.push(make_pair(j, temp));if (p().first] < vec[j])st.push(make_pair(j, temp));}}}cout << ans << endl;
}
转载于:.html
本文发布于:2024-02-01 12:19:38,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170676118036547.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |