//本题大意是对于一个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. BeeFramework 系列

    http://ilikeido.iteye.com/category/281079 BeeFramework 系列三 MVC篇上 博客分类: Beeframework iphone开发 mvc框架Be ...

  2. Linux系统调用--getrlimit()与setrlimit()函数详解【转】

    转自:http://www.cnblogs.com/niocai/archive/2012/04/01/2428128.html 功能描述:获取或设定资源使用限制.每种资源都有相关的软硬限制,软限制是 ...

  3. CyanogenMod编译

    1. 介绍 本文介绍了i9100手机CyanogenMod 13系统的编译方法 2. 系统要求 笔者使用的环境为CentOS-7-x86_64, 用来为i9100编译CM 13,之所以选择最新版的CM ...

  4. (七)insmod/rmmod

    insmod: insmod命令用于将给定的模块加载到内核中.Linux有许多功能是通过模块的方式,在需要时才载入kernel.如此可使kernel较为精简,进而提高效率,以及保有较大的弹性.这类可载 ...

  5. 关闭vs警告

    禁用所有编译器警告 当“解决方案资源管理器”中有项目选中时,在“项目”菜单上单击“属性”. 单击“编译”选项卡. 选中“禁用所有警告”复选框. 禁用单个编译器警告 在“解决方案资源管理器”中选定一个项 ...

  6. js常用函数总结

    字符串函数 indexOf 返回字符串中一个子串第一处出现的索引(从左到右搜索).如果没有匹配项,返回 -1 . var index1 = a.indexOf("l"); //in ...

  7. windows下xampp安装PHP的pthreads多线程扩展

    我的运行环境: 系统:windows10 ,64位 PHP:5.6.8 TS,VC11 ,32位 Apache: 2.0 我安装的是xampp集成环境 pthreads的windows扩展文件下载地址 ...

  8. hdu 3635(并查集)

    Dragon Balls Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tota ...

  9. 洛谷——1164 小A点菜(背包方案数)

    大水题!! 题目背景 uim神犇拿到了uoi的ra(镭牌)后,立刻拉着基友小A到了一家……餐馆,很低端的那种. uim指着墙上的价目表(太低级了没有菜单),说:“随便点”. 题目描述 不过uim由于买 ...

  10. [HDU6240]Server

    题目大意: 用$n$条线段覆盖区间$[1,t]$上的整点.每条线段有4个属性$(S_i,T_i,A_i,B_i)$,表示用第$i$条线段可以覆盖区间$[S_i,T_i]$.若选取线段的集合为$S$,最 ...