//本题大意是对于一个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. 免费的二维码发布平台 http://zhifubao.masao.top:8282/assets/index.html

    http://zhifubao.masao.top:8282/assets/index.html

  2. [LeetCode] Combinations 回溯

    Given two integers n and k, return all possible combinations of k numbers out of 1 ... n. For exampl ...

  3. JSP中的:request.getScheme()+"://"+request.getServerName()+":"+request.getServer

    String path = request.getContextPath();  String basePath = request.getScheme()+"://"+reque ...

  4. Microsoft SilverLightt是一个跨浏览器的、跨平台的插件,为网络带来下一代基于.NETFramework的媒体体验和丰富的交互式应用程序。

    Microsoft Silverlight是一个跨浏览器的.跨平台的插件,为网络带来下一代基于.NETFramework的媒体体验和丰富的交互式应用程序.Silverlight提供灵活的编程模型,并可 ...

  5. (九)ubuntu解决resolv.conf被重写问题

    解决resolv.conf被重写问题 来源:http://www.cnblogs.com/lanxuezaipiao/p/3613497.html 第二步中你虽然配置了DNS,但是每次重启虚拟机或重启 ...

  6. python bisect模块二分法查找

    #!/usr/bin/env python # encoding: utf-8 import bisect import sys #将一个元素插入到一个有序列表的合适位置 #使用这个模块的函数前先确保 ...

  7. C++ bitset类的使用与简介 [转载]

    有些程序要处理二进制位的有序集,每个位可能包含的是0(关)或1(开)的值.位是用来保存一组项或条件的yes/no信息(有时也称标志)的简洁方法.标准库提供了bitset类使得处理位集合更容易一些.要使 ...

  8. BufferedInputStream&BufferedOutputStream

    使用字符缓冲区相关实现copy文件: public static void main(String[] args) { //创建文件对象指定要拷贝的文件路径(源文件),文件须存在,测试用例不做判断 F ...

  9. python爬虫搜片利器fmovice【转载】

    本篇转自博客:上海-悠悠 原文地址:http://www.cnblogs.com/yoyoketang/tag/python/ 前言 讲真!小编不管看什么电影(大的.小的),不管什么电视剧,小编都没买 ...

  10. 开发框架 springBoot

    1.多个环境的配置文件 在application.yml 中配置需要调用的配置文件 spring: profiles: active: dev 运行方式的,先运行application.yml 再根据 ...