SOL 奇奇怪怪的贪心(你也不要问我为什么)
#include<bits/stdc++.h> #define N 1007 int f[N][N],sum,ans,Ha,bo,n,Ans; #define MARICLE __attribute__((optimize("-O3"))) char ch,mp[N][N]; using namespace std; MARICLE void write(int x) {if (x<10) {putchar(‘0‘+x);return;} write(x/10); putchar(‘0‘+x%10);} MARICLE inline void writeln(int x) {if (x<0) putchar(‘-‘),x*=-1; write(x); putchar(‘\n‘);} MARICLE int main () { // freopen("a.in","r",stdin); scanf("%d\n",&n); for (int i=1; i<=n; ++i) scanf("%s", mp[i]+1); for (int i=1;i<=n;i++) for (int j=1;j<=n;j++) f[i][j]=(mp[i][j]==‘#‘),sum+=f[i][j]; Ans=1e9; if (!sum) {writeln(-1);return 0;} for (int i=1;i<=n;i++) {bo=1; for (int j=1;j<=n;j++) bo&=f[j][i]; Ha+=1-bo; } for (int i=1;i<=n;i++) { ans=0;bo=0; for (int j=1;j<=n;j++) ans+=f[i][j],bo|=f[j][i]; ans=n-ans; if (!ans) {Ans=0;break;} Ans=min(ans+1-bo,Ans); } writeln(Ans+Ha);return 0; }