https://codeforc.es/contest/1194/problem/B
好像也没什么思维,就是一个水题,不过蛮有趣的。意思是找缺黑色最少的行列十字。用O(n)的空间预处理掉一维,然后用O(n)的时间根据另一维计算出答案。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n, m;
string g[50005];
int rq[50005];
int main() {
#ifdef Yinku
freopen("Yinku.in", "r", stdin);
//freopen("Yinku.out", "w", stdout);
#endif // Yinku
int q;
while(~scanf("%d", &q)) {
while(q--) {
scanf("%d%d", &n, &m);
for(int i = 1; i <= n; i++) {
cin >> g[i];
g[i] = '$' + g[i];
}
int minans = n * m;
for(int i = 1; i <= n; i++) {
rq[i] = 0;
for(int j = 1; j <= m; j++) {
if(g[i][j] == '.') {
rq[i]++;
}
}
}
for(int j = 1; j <= m; j++) {
int cq = 0;
for(int i = 1; i <= n; i++) {
if(g[i][j] == '.') {
cq++;
}
}
for(int i = 1; i <= n; i++) {
minans = min(minans, rq[i] + cq - (g[i][j] == '.'));
}
}
printf("%d
",minans);
}
}
}