• BZOJ 1059: [ZJOI2007]矩阵游戏( 匈牙利 )


    只要存在N个x, y坐标均不相同的黑格, 那么就一定有解. 二分图匹配, 假如最大匹配=N就是有解的, 否则无解 

    ----------------------------------------------------------------------------------

    #include<cstdio>
    #include<cstring>
    #include<algorithm>
     
    using namespace std;
     
    const int maxn = 209;
     
    struct edge {
    int to;
    edge* next;
    } E[50000], *pt, *head[maxn];
     
    void addedge(int u, int v) {
    pt->to = v; pt->next = head[u]; head[u] = pt++;
    }
     
    int vis[maxn], match[maxn];
    int N, C;
     
    void init() {
    pt = E;
    memset(head, 0, sizeof head);
    memset(vis, -1, sizeof vis);
    memset(match, -1, sizeof match);
    }
     
    bool dfs(int x) {
    for(edge* e = head[x]; e; e = e->next) if(vis[e->to] != C) {
    vis[e->to] = C;
    if(!~match[e->to] || dfs(match[e->to])) {
    match[e->to] = x;
    return true;
    }
    }
    return false;
    }
     
    int main() {
    int T; scanf("%d", &T);
    while(T--) {
    init();
    scanf("%d", &N);
    for(int i = 0; i < N; i++)
    for(int j = 0; j < N; j++) {
    int t; scanf("%d", &t);
    if(t) addedge(i, j);
    }
    int cnt = 0;
    for(C = 0; C < N; C++) if(dfs(C)) cnt++;
    puts(cnt == N ? "Yes" : "No");
    }
    return 0;
    }

    ----------------------------------------------------------------------------------

    1059: [ZJOI2007]矩阵游戏

    Time Limit: 10 Sec  Memory Limit: 162 MB
    Submit: 2889  Solved: 1401
    [Submit][Status][Discuss]

    Description

    小Q是一个非常聪明的孩子,除了国际象棋,他还很喜欢玩一个电脑益智游戏——矩阵游戏。矩阵游戏在一个N*N黑白方阵进行(如同国际象棋一般,只是颜色是随意的)。每次可以对该矩阵进行两种操作:行交换操作:选择矩阵的任意两行,交换这两行(即交换对应格子的颜色)列交换操作:选择矩阵的任意行列,交换这两列(即交换对应格子的颜色)游戏的目标,即通过若干次操作,使得方阵的主对角线(左上角到右下角的连线)上的格子均为黑色。对于某些关卡,小Q百思不得其解,以致他开始怀疑这些关卡是不是根本就是无解的!!于是小Q决定写一个程序来判断这些关卡是否有解。

    Input

    第一行包含一个整数T,表示数据的组数。接下来包含T组数据,每组数据第一行为一个整数N,表示方阵的大小;接下来N行为一个N*N的01矩阵(0表示白色,1表示黑色)。

    Output

    输出文件应包含T行。对于每一组数据,如果该关卡有解,输出一行Yes;否则输出一行No。

    Sample Input

    2
    2
    0 0
    0 1
    3
    0 0 1
    0 1 0
    1 0 0

    Sample Output

    No
    Yes
    【数据规模】
    对于100%的数据,N ≤ 200

    HINT

    Source

  • 相关阅读:
    confluence --常用插件整合
    fuse--s3挂载到centos7.5服务器
    gvm--go版本管理工具
    等保1.0与等保2.0的区别
    postfix -- 发件调试
    postfix邮件服务器
    confluence -- 命令行备份还原
    浏览器使用小tip
    windows如何正确下载补丁包
    xwiki使用中的问题
  • 原文地址:https://www.cnblogs.com/JSZX11556/p/4929710.html
Copyright © 2020-2023  润新知