• 矩阵[雅礼集训 2017 Day1]


    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('
    ');}
    MARICLE int main () {
    //  freopen("a.in","r",stdin);
        scanf("%d
    ",&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;
    }
  • 相关阅读:
    高二下期末考试
    LG月赛.7
    CF1187E
    P5440 【XR-2】奇迹
    P1084 疫情控制
    P1083 借教室
    P2680 运输计划
    P3128 [USACO15DEC]最大流Max Flow
    博弈入门
    HDU 1907
  • 原文地址:https://www.cnblogs.com/rrsb/p/8215139.html
Copyright © 2020-2023  润新知