//本题大意是对于一个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. [ CodeVS冲杯之路 ] P3038

    不充钱,你怎么AC? 题目:http://codevs.cn/problem/3038/ 按照题目给定的方法,一步步推下去,直到推到1就输出次数 至于-1的话,一开始想直接用数组判重,但是怕T掉,于是 ...

  2. Linux下的GitHub安装与简单配置教程 ~ 转载

    Linux下的GitHub安装与简单配置教程   1.GitHub简介 Git是一个分布式版本控制系统,与其相对的是CVS.SVN等集中式的版本控制系统. 2.Git的安装 1)安装Git a.查看与 ...

  3. source insight setting

    adjust source code font size Options -> File Type Options -> Screen Font -> Size adjust dis ...

  4. POCO库中文编程参考指南(3)Poco::Net::Socket

    POCO库中文编程参考指南(3)Poco::Net::Socket 作者:柳大·Poechant 博客:Blog.CSDN.net/Poechant 邮箱:zhongchao.ustc#gmail.c ...

  5. POCO库中文编程参考指南(1)总览

    POCO库中文编程参考指南(1)总览 作者:柳大·Poechant 博客:Blog.CSDN.net/Poechant 邮箱:zhongchao.ustc#gmail.com (# -> @) ...

  6. Flask-Migrate拓展数据库表结构

    # 转载请留言联系 在我们用 sqlchemy 模块创建完几个表时,如果在实际生产环境中,需要对表结构进行更改,应该怎么办呢?总不能把表删除了吧,这样数据就会丢失了. 更好的解决办法是使用数据库迁移框 ...

  7. js-限制参与活动的范围(微信H5活动)

    近期接到大连某个项目,一个H5的活动,其中有一个需求就是:这个活动的参与者仅限大连地区的用户 所以参考了微信API 得出的操作结果为: wx.ready(function() { wx.getLoca ...

  8. 51nod 1091 线段的重叠【贪心/区间覆盖类】

    1091 线段的重叠 基准时间限制:1 秒 空间限制:131072 KB 分值: 5 难度:1级算法题  收藏  关注 X轴上有N条线段,每条线段包括1个起点和终点.线段的重叠是这样来算的,[10 2 ...

  9. SpringBoot日志管理

    一.简介 小张:开发一个大型系统:1.System.out.println(""):将关键数据打印在控制台:去掉?写在一个文件?2.框架来记录系统的一些运行时信息:日志框架 : z ...

  10. 洛谷——P1706 全排列问题

    P1706 全排列问题 题目描述 输出自然数1到n所有不重复的排列,即n的全排列,要求所产生的任一数字序列中不允许出现重复的数字. 输入输出格式 输入格式: n(1≤n≤9) 输出格式: 由1-n组成 ...