//本题大意是对于一个r*c的矩阵,每一列有两个是白色的

//如今选c个位置,要求每一行至少有一个白色的方格被选上

//每一列仅仅能选一个

//用二分匹配求出最大匹配,假设最大匹配等于r,则满足

//每一行至少有一个白色的格子被选上

//注意c>r的情况

#include<iostream>

#include<cstdio>

#include<cstring>

using namespace std;

const int maxn = 1010;

int line[maxn][maxn];

int match[maxn];

int match_ans[maxn];

int vis[maxn];

int r,c;

int find(int start)

{

    int i ;

    for(i=1;i<=r;i++)

    {

        if(line[start][i]&&!vis[i])

        {

            vis[i]=1;

            if(match[i]==-1||find(match[i]))

            {

                match[i] = start ;

                match_ans[start] = i;

                return 1;

            }

        }

    }

    return 0;

}

void Match()

{

    int i;

    memset(match , -1 ,sizeof(match));

    int ans = 0;

    for(i = 1; i <= c;i++)

    {

       memset(vis , 0 , sizeof(vis));

       if(find(i))

       ans++;

    }

    if(ans == r)

    {

        for(i = 1;i <= c; i++)

        {

            if(!match_ans[i])

            {

                for(int j = 1;j <= r ;j++)

                if(line[i][j])

                {

                    printf("%d%c",j,i == c?'\n':' ');

                    break;

                }

            }

            else

            printf("%d%c",match_ans[i],i == c?

'\n':' ');

        }

    }

    else

    printf("NO\n");

}

int main()

{

   //freopen("in.txt", "r" ,stdin);

    int T;

    scanf("%d", &T);

    while(T--)

    {

        memset(line, 0 ,sizeof(line));

        memset(match_ans , 0 ,sizeof(match_ans));

        scanf("%d%d" ,&r , &c);

        int a,b;

        for(int i = 1; i <= c ;i++)

        {

            scanf("%d%d",&a ,&b);

            line[i][a] = line[i][b] = 1;

        }

        Match();

    }

    return 1;

}

poj 1719Shooting Contest的更多相关文章

  1. poj 3660Cow Contest

    题目链接:http://poj.org/problem?id=3660 有n头奶牛还有m种关系a,b表示a牛逼b彩笔,所以a排名比b高 最后问你给出的关系最多能确定多少头奶牛的排名,而且给出的数据不会 ...

  2. POJ 3204 Ikki's Story I - Road Reconstruction

    Ikki's Story I - Road Reconstruction Time Limit: 2000MS   Memory Limit: 131072K Total Submissions: 7 ...

  3. POJ 3744 Scout YYF I

    分段的概率DP+矩阵快速幂                        Scout YYF I Time Limit: 1000MS   Memory Limit: 65536K Total Sub ...

  4. [最近公共祖先] POJ 3728 The merchant

    The merchant Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 4556   Accepted: 1576 Desc ...

  5. POJ 3278 The merchant

    传送门 Time Limit: 3000MS Memory Limit: 65536K Description There are N cities in a country, and there i ...

  6. Scout YYF I(POJ 3744)

    Scout YYF I Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5565   Accepted: 1553 Descr ...

  7. poj 3744 Scout YYF I (矩阵)

    Description YYF -p. Here is the task, given the place of each mine, please calculate the probality t ...

  8. [POJ 3734] Blocks (矩阵高速幂、组合数学)

    Blocks Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3997   Accepted: 1775 Descriptio ...

  9. poj 3728 The merchant(LCA)

    Description There are N cities in a country, and there is one and only one simple path between each ...

随机推荐

  1. npoi导出excel 导出List<T>

    using System.Collections.Generic; using NPOI.HSSF.UserModel; using NPOI.SS.UserModel; using NPOI.XSS ...

  2. median(NOIP模拟赛Round 3)

    也是神奇的题目.. 原题传送门 首先看到这道题目,很明显我们需要线性算法 1.前缀和+统计 2.DP+统计 对于第一种算法,我们可以对于任何一个a[i]对b进行比较,如果大于b标上1,等于b标上0,小 ...

  3. matlab多行注释的三种方法

    转自:http://icictech.blog.163.com/blog/static/2797425420084595725499/ 1)方法一 选中你要加注释的内容,然后选择工具菜单"t ...

  4. dll共享段中一些需要注意的问题

    Visual C++ 如何与应用程序或其他 DLL 共享自己 DLL 中的数据? Win32 DLL 映射到调用进程的地址空间中.默认情况下,每个使用 DLL 的进程都有自己的所有 DLL 全局变量和 ...

  5. Jquery操作基本筛选过滤器

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  6. hdu 5062(水题)

    Beautiful Palindrome Number Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 32768/32768 K (J ...

  7. hdu 1102(最小生成树)

    Constructing Roads Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  8. spring3.2事物配置异常

    异常如下: org.springframework.beans.factory.support.DefaultListableBeanFactory@1b4c1d7: defining beans [ ...

  9. 牛客网 暑期ACM多校训练营(第二场)I.car-规律思维题

    I.car 车只能从一边走到另一边,而且车和车不能相撞,车也不能走到坑里.所以直接找规律,如果没有坑,最多能放多少辆车.就会发现,关于对角线对称的两边只能放一辆车,如果是奇数个的时候,中间的行和中间的 ...

  10. java标识符与命名规则

    标识符就是给变量.类或方法起的名字.可以用字母.下划线或美元符号开头,区分大小写,没有最大长度限制.(关键字除外) 关键字   访问控制 private protected public       ...