矩陣[雅禮集訓 2017 Day1]
阿新 • • 發佈:2018-01-06
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 inlinevoid 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]