//本题大意是对于一个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. 自定义topo遇到的坑

    错误:TypeError: __init__() got an unexpected keyword argument 'delay' 解决办法:在创建topo的地方加一个link=TCLink即可, ...

  2. Reporting Services 的一些问题

    做报表有一段时间,感觉Reporting Services还是比较麻烦的,因为网上的例子有的比较少,很多地方都需要自己摸索,说说我遇到的一些问题 1:页首的设计 一些固定显示的资料放在页首里面比较方便 ...

  3. css实现web前端最美的loading加载动画!

    这些好看的loading效果,你还只会用第三方库吗?CSS3教你实现 ​前言 loading效果在实际开发中是很常见的,尤其是在Ajax请求的时候,可以给用户一个很好的交互体验. 今天这篇文章我们一起 ...

  4. Web前端培训学习心得

    web前端工程师技术日趋成熟,越来越多的行业巨头正不断向web前端工程师示好,在未来几年,web前端将会以更多的形式渗透到我们生活中的方方面面,因此越来越多的从业者开始关注web前端开发行业,今天小编 ...

  5. POJ 2184 Cow Exhibition【01背包+负数(经典)】

    POJ-2184 [题意]: 有n头牛,每头牛有自己的聪明值和幽默值,选出几头牛使得选出牛的聪明值总和大于0.幽默值总和大于0,求聪明值和幽默值总和相加最大为多少. [分析]:变种的01背包,可以把幽 ...

  6. NMAP输出结果中CPE的含义

    NMAP输出结果中CPE的含义   CPE全称是Common Platform Enumeration,意思是通用平台枚举项.它是NMAP对识别出来的软件.操作系统和硬件的一种命名方式.它的格式如下: ...

  7. 前端中 width 的获取

    这篇文章其实是在了解 viewport 的过程中发现这些概念容易混淆做了个小小的总结.viewport的首要关键是宽度的获取,宽度的计算有下面几个属性和方法: clientWidth offsetWi ...

  8. 【bzoj3687】【简单题】bitset

    [pixiv] https://www.pixiv.net/member_illust.php?mode=medium&illust_id=64333782 这次的图是自己画的,方便的话点个赞 ...

  9. 【bzoj4808】【马】二分图最大点独立集+简单感性证明

    (上不了p站我要死了,侵权度娘背锅) Description 众所周知,马后炮是中国象棋中很厉害的一招必杀技."马走日字".本来,如果在要去的方向有别的棋子挡住(俗称"蹩 ...

  10. 【hdu1150】【Machine Schedule】二分图最小点覆盖+简单感性证明

    (上不了p站我要死了,侵权度娘背锅) 题目大意 有两台机器A和B以及N个需要运行的任务.每台机器有M种不同的模式,而每个任务都恰好在一台机器上运行.如果它在机器A上运行,则机器A需要设置为模式ai,如 ...