1. 程式人生 > >矩陣[雅禮集訓 2017 Day1]

矩陣[雅禮集訓 2017 Day1]

n) upload -o3 技術 utc line clu ace day

技術分享圖片

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; }

矩陣[雅禮集訓 2017 Day1]