题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2119

Matrix

Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2205    Accepted Submission(s):
975

Problem Description
Give you a matrix(only contains 0 or 1),every time you
can select a row or a column and delete all the '1' in this row or this column
.

Your task is to give out the minimum times of deleting all the '1' in
the matrix.

 
Input
There are several test cases.

The first line
contains two integers n,m(1<=n,m<=100), n is the number of rows of the
given matrix and m is the number of columns of the given matrix.
The next n
lines describe the matrix:each line contains m integer, which may be either ‘1’
or ‘0’.

n=0 indicate the end of input.

 
Output
For each of the test cases, in the order given in the
input, print one line containing the minimum times of deleting all the '1' in
the matrix.
 
Sample Input
3 3
0 0 0
1 0 1
0 1 0
0
 
Sample Output
2
 
Author
Wendell
 
 
Source
 
题目大意:将矩阵所给的1全部变成0,每次改变可以变换一行或者一列。问最少多少次,可以使矩阵里的所有元素全部变为0?
解题思路:将横坐标X看做二分图的左支,纵坐标Y看做二分图的右支。求二分图的最小点覆盖=二分图的最匹配数。
 
详见代码。
 #include <iostream>
#include <cstdio>
#include <cstring> using namespace std; int vis[],Map[][];
int ok[],n,m; bool Find(int x)
{
for (int i=;i<m;i++)
{
if (Map[x][i]==&&!vis[i])
{
vis[i]=;
if (ok[i]==-)
{
ok[i]=x;
return true;
}
else
{
if (Find(ok[i])==true)
{
ok[i]=x;
return true;
}
}
}
}
return false;
} int main()
{
int ans;
while (~scanf("%d",&n))
{
ans=;
if (n==)
break;
scanf("%d",&m);
memset(Map,,sizeof(Map));
memset(ok,-,sizeof(ok));
for (int i=;i<n;i++)
{
for (int j=;j<m;j++)
{
scanf("%d",&Map[i][j]);
}
}
for (int i=;i<n;i++)
{
memset(vis,,sizeof(vis));
if (Find(i))
{
ans++;
}
}
printf ("%d\n",ans);
}
return ;
}
 
 
 

hdu 2119 Matrix(二分匹配)的更多相关文章

  1. hdu 1281棋盘游戏(二分匹配)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1281   Problem Description 小希和Gardon在玩一个游戏:对一个N*M的棋盘, ...

  2. HDU 3468 BFS+二分匹配

    九野的博客,转载请注明出处 http://blog.csdn.net/acmmmm/article/details/10966383 开始建图打搓了,参考了大牛的题解打的版本比较清爽,后来改的基本雷同 ...

  3. HDU 2819 Swap (二分匹配+破输出)

    题意:给定上一个01矩阵,让你变成一个对角全是 1 的矩阵. 析:二分匹配,把行和列看成两个集合,用匈牙利算法就可以解决,主要是在输出解,在比赛时一紧张不知道怎么输出了. 输出应该是要把 match[ ...

  4. HDU 2819 — Swap 二分匹配

    Swap Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  5. HDU 2119 Matrix

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2119 解题思路: 处理数据,使用公式最小点覆盖数=最大匹配数,使用匈牙利算法求二分图最大匹配即可. ...

  6. hdu 1281 棋盘游戏 (二分匹配)

    棋盘游戏 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

  7. HDU——2119 Matrix

    Matrix Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Sub ...

  8. Hdu 1498 二分匹配

    50 years, 50 colors Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

  9. Fire Net HDU - 1045(二分匹配)

    把每一列中相邻的 .  缩为一个点 作为二分图的左边 把每一行中相邻的  .  缩为一个点 作为二分图的右边 然后求最大匹配即可 这题用匈牙利足够了...然而..我用了hk...有点大材小用的感觉// ...

随机推荐

  1. xheditor在线编辑器在.netMVC4中的使用

    在线编辑器xheditor,测试感觉不错,特把使用方法记录如下 : 先看看基本使用方法,然后用实例来操作 1.xheditor 地址 http://xheditor.com/ 2.下载最新编辑器源码 ...

  2. MySQL配置文件简单解析

    [mysqld] basedir = /data/mysql datadir = /data/mysqldata tmpdir = /data/mysqltmpdata //mysql的查询临时目录, ...

  3. hive 排序和聚集

    1.order by 是对数据进行全排序,属于标准排序语句 order by 会对输入做全局排序,因此只有一个reducer(多个reducer无法保证全局有序)只有一个reducer,会导致当输入规 ...

  4. 聊聊flink的AsyncWaitOperator

    序本文主要研究一下flink的AsyncWaitOperator AsyncWaitOperatorflink-streaming-java_2.11-1.7.0-sources.jar!/org/a ...

  5. 【移动支付】.NET微信扫码支付接入(模式二-NATIVE)

    一.前言       经过两三天的琢磨总算完成了微信扫码支付功能,不得不感叹几句: 微信提供的DEMO不错,直接复制粘贴就可以跑起来了: 微信的配置平台我真是服了.公众平台.商户平台.开放平台,一个平 ...

  6. 【CF600E】Lomsat gelral(dsu on tree)

    [CF600E]Lomsat gelral(dsu on tree) 题面 洛谷 CF题面自己去找找吧. 题解 \(dsu\ on\ tree\)板子题 其实就是做子树询问的一个较快的方法. 对于子树 ...

  7. 【BZOJ2780】【SPOJ】Sevenk Love Oimaster(后缀自动机)

    [BZOJ2780][SPOJ]Sevenk Love Oimaster(后缀自动机) 题面 BZOJ 洛谷 题解 裸的广义后缀自动机??? 建立广义后缀自动机建立出来之后算一下每个节点被几个串给包括 ...

  8. [持续更新][备份]GDB调试工具常用命令

    一.前言 ACM开赛在即,得知dev-cpp不适用之后,不得不再次重拾gdb基本操作... 辗转Emacs和Code::blocks数次之后,感觉还是Emacs更适合我的风格,尽管配置稍显麻烦,但其开 ...

  9. 【bzoj4182】shopping

    Portal --> bzoj4182 Solution 感天动地..几百年没在场上写点分了的感觉== (然后就写了很久qwq) ​ 不过感觉自己想这道题怎么颇有运气成分==大概是:诶是不是快乐 ...

  10. Spring MVC同时接收一个对象与List集合对象

    原:https://blog.csdn.net/u011781521/article/details/77586688/ Spring MVC同时接收一个对象与List集合对象 2017年08月25日 ...