1 条题解

  • 0
    @ 2025-10-8 17:11:25
    #include <cstdlib>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <algorithm>
    using namespace std;
    
    struct edge{
        int next,to;
    }e[1000005];
    int ade,n,m,cnt,T,c;
    int x[]={1,2,-1,-2,-1,2,1,-2};
    int y[]={2,1,-2,-1,2,-1,-2,1};
    int mp[205][205],id[205][205],first[1000005],vis[1000005],match[1000005];
    
    void addedge(int x,int y){
        e[++ade].next=first[x];
        e[ade].to=y;
        first[x]=ade;
    }
    
    bool check(int x,int y){
        return (x>=1 && x<=n && y>=1 && y<=m && !mp[x][y]);
    }
    
    #define s e[x].to
    bool hungary(int p){
        for (int x=first[p];x;x=e[x].next){
            if (vis[s]!=T){
                vis[s]=T;
                if (!match[s] || hungary(match[s])) {match[s]=p; return 1;}
            }
        }
        return 0;
    }
    #undef s
    
    int main(){
        scanf("%d%d",&n,&m);
        for (int i=1;i<=n;i++){
            for (int j=1;j<=m;j++){
                scanf("%d",&mp[i][j]);
                cnt+=(!mp[i][j]);
                id[i][j]=++c;
            }
        }
        for (int i=1;i<=n;i++)
            for (int j=1;j<=m;j++)
                if (((i+j)&1) && !mp[i][j])for (int k=0;k<8;k++) if (check(i+x[k],j+y[k])) addedge(id[i][j],id[i+x[k]][j+y[k]]);
        for (int i=1;i<=n;i++){
            for (int j=1;j<=m;j++){
                if (!mp[i][j] && ((i+j)&1)){
                    T=id[i][j];
                    cnt-=hungary(T);
                }
            }
        }
        printf("%d\n",cnt);
        return 0;
    }
    
    • 1

    信息

    ID
    6477
    时间
    1000ms
    内存
    256MiB
    难度
    7
    标签
    递交数
    49
    已通过
    13
    上传者