很离谱,我用PII stk[N * N],代替vector在输入30*30的大数据时,我的n = 23,m = 18。调试了半天没搞明白,最后用vector一遍过!!!!
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
typedef pair<int,int> PII;
const int N = 40;
int g[N][N];
// PII stk[N * N];
vector<PII> stk;
// int tt = -1;
int n,m;
int main(){
cin >> n >> m;
int p = n,l = m;
for(int i = 1;i <= n;i++)
for(int j = 1;j <= m;j++)
cin >> g[i][j];
// cout << n << ' ' << m << endl;
for(int k = 1;k <= n;k++){
for(int j = 1;j <= m;j++){
int times = 1,val = g[k][j],x = j;
stk.push_back({k,j});
// stk[++tt] = ;
for(int i = j + 1;i <= m;i++){
if(val == g[k][i] && val != 0 && i - x == 1){
times++;
stk.push_back({k,i});
x = i;
}
}
if(times < 3)
while(times--) stk.pop_back();
}
}
for(int k = 1;k <= m;k++){
for(int j = 1;j <= n;j++){
int times = 1,val = g[j][k],x = j;
stk.push_back({j,k});
for(int i = j + 1;i <= n;i++){
if(val == g[i][k] && val != 0 && i - x == 1){
times++;
stk.push_back({i,k});
x = i;
}
}
if(times < 3)
while(times--) stk.pop_back();
}
}
for(int i = 0;i < stk.size();i++){
auto t = stk[i];
g[t.first][t.second] = 0;
}
for(int i = 1;i <= n;i++){
for(int j = 1;j <= m;j++){
cout << g[i][j] << ' ';
}
cout << endl;
}
return 0;
}