hdu 1498 50 years, 50 colors(二分匹配_匈牙利算法)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1498
50 years, 50 colors
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1918 Accepted Submission(s):
1058
balloons floating around the campus, it's so nice, isn't it? To celebrate this
meaningful day, the ACM team of HDU hold some fuuny games. Especially, there
will be a game named "crashing color balloons".
There will be a n*n
matrix board on the ground, and each grid will have a color balloon in it.And
the color of the ballon will be in the range of [1, 50].After the referee shouts
"go!",you can begin to crash the balloons.Every time you can only choose one
kind of balloon to crash, we define that the two balloons with the same color
belong to the same kind.What's more, each time you can only choose a single row
or column of balloon, and crash the balloons that with the color you had chosen.
Of course, a lot of students are waiting to play this game, so we just give
every student k times to crash the balloons.
Here comes the problem:
which kind of balloon is impossible to be all crashed by a student in k
times.

begins with two integers n, k. n is the number of rows and columns of the
balloons (1 <= n <= 100), and k is the times that ginving to each
student(0 < k <= n).Follow a matrix A of n*n, where Aij denote the color
of the ballon in the i row, j column.Input ends with n = k = 0.
colors of which are impossible to be crashed by a student in k times. If there
is no choice, print "-1".
#include <iostream>
#include <cstdio>
#include <cstring> using namespace std; int n,m;
int vis[],Map[][],ok[],cc[]; bool Find(int x,int now)
{
for (int i=; i<=n; i++)
{
if (!vis[i]&&Map[x][i]==now)
{
vis[i]=;
if (!ok[i])
{
ok[i]=x;
return true;
}
else
{
if (Find(ok[i],now))
{
ok[i]=x;
return true;
}
}
}
}
return false;
} int main()
{
int flag,ans,s[];
while (~scanf("%d%d",&n,&m))
{
flag=;
memset(cc,,sizeof(cc));
memset(Map,,sizeof(Map));
if (n==&&m==)
break;
for (int i=; i<=n; i++)
{
for (int j=; j<=n; j++)
{
scanf("%d",&Map[i][j]);
cc[Map[i][j]]=;//记录这个颜色出现过
}
}
memset(ok,,sizeof(ok));
int k=;
for (int i=; i<=; i++)
{
memset(ok,,sizeof(ok));
ans=;
if (cc[i]==) //判断颜色是否出现过,加入这里不进行标记的话最后输出的是没有被刷完的颜色数字,就会输出一些乱七八糟的东西
{
for (int j=; j<=n; j++)
{
memset(vis,,sizeof(vis));
if (Find(j,i))
ans++;
}
if (ans>m) //如果最大匹配数大于m次的话就是刷不完的
{
s[++k]=i;
flag=;
}
}
}
if (flag==)
printf ("-1\n");
else
{
for (int i=; i<k; i++) //控制输出格式
{
printf ("%d ",s[i]);
}
printf ("%d\n",s[k]);
}
}
return ;
}
hdu 1498 50 years, 50 colors(二分匹配_匈牙利算法)的更多相关文章
- hdu 3729 I'm Telling the Truth(二分匹配_ 匈牙利算法)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3729 I'm Telling the Truth Time Limit: 2000/1000 MS ( ...
- HDU 1150:Machine Schedule(二分匹配,匈牙利算法)
Machine Schedule Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- hdu2063 最大二分匹配(匈牙利算法)
过山车 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
- hdu 2063 过山车 二分匹配(匈牙利算法)
简单题hdu2063 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2063 过山车 Time Limit: 1000/1000 MS (Java/Ot ...
- POJ 3014:Asteroids(二分匹配,匈牙利算法)
id=3041">Asteroids Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 14399 Acce ...
- 二分图的最大匹配以及带权匹配【匈牙利算法+KM算法】
二分图算法包括 匈牙利算法 与 KM算法. 匈牙利算法 在这里写上模板. 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2063 #include< ...
- HDU5090--Game with Pearls 二分图匹配 (匈牙利算法)
题意:给N个容器,每个容器里有一定数目的珍珠,现在Jerry开始在管子上面再放一些珍珠,放上的珍珠数必须是K的倍数,可以不放.最后将容器排序,如果可以做到第i个容器上面有i个珍珠,则Jerry胜出,反 ...
- HDU 6178 Monkeys(树上的二分匹配)
http://acm.hdu.edu.cn/showproblem.php?pid=6178 题意:现在有一n个顶点的树形图,还有k只猴子,每个顶点只能容纳一只猴子,而且每只猴子至少和另外一只猴子通过 ...
- HDU - 3081 Marriage Match II 【二分匹配】
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=3081 题意 有n对男女 女生去选男朋友 如果女生从来没和那个男生吵架 那么那个男生就可以当她男朋友 女 ...
随机推荐
- Mware中CentOS设置静态IP
Mware中CentOS设置静态IP 因为之前搭建的MongoDB分片没有采用副本集,最近现网压力较大,所以准备研究一下,于是在自己电脑的虚拟机中搭建环境,但是发现之前VMware设置的是DHCP ...
- ASP.NET存储Session的StateServer
由于公司要对服务器做个负载均衡,所以Web项目在两台前端服务器(web1.web2)各部署了一份.但是在项目中会用到session.当一开始在web1上登陆后,由于web1之后负载可能会变大,就有可能 ...
- linux安装py3.6
随手记录: https://www.python.org/ftp/python/3.6.8/Python-3.6.8rc1.tgz 所有linux版本: https://www.python.org/ ...
- WCF跨时区自动转换问题
背景:api端 用wcf做的 客户端是silverlight, 服务和消费 不是同一个时区 状况:客户端调用返回对象有个字段是datetime ,返回的时间和数据库相差好几个小时,找了很久,最后把da ...
- 第146天:移动H5前端性能优化
移动H5前端性能优化 一.概述 1. PC优化手段在Mobile侧同样适用 2. 在Mobile侧我们提出三秒种渲染完成首屏指标 3. 基于第二点,首屏加载3秒完成或使用Loading 4. 基于联通 ...
- CF464C-Substitutes in Number
题意 开始给出一个长为\(n\)的数字串,有\(m\)次操作按顺序执行,每次把当前数字串中的某一个数码替换成一个数字串\(t\)(可以为空或多位),最后问操作结束后的数字串十进制下模\(10^9+7\ ...
- 【bzoj1297】[SCOI2009]迷路 矩阵乘法
题目描述 给出一个 $n$ 个点的有向图,每条边的权值都在 $[1,9]$ 之间.给出 $t$ ,求从 $1$ 到 $n$ ,经过路径边权和恰好为 $t$ 的方案数模2009. 输入 第一行包含两个整 ...
- php获取字符串的编码格式的方法(函数)
// 检测字符的编码格式 $encode = mb_detect_encoding($string, array('ASCII','UTF-8','GB2312','GBK','BIG5')); ec ...
- [CQOI2013]新Nim游戏 线性基
题面 题面 题解 首先我们知道nim游戏先手必败当且仅当所有石堆异或和为0,因此我们的目标就是要使对手拿石堆的时候,无论如何都不能使剩下的石堆异或和为0. 对于一个局面,如果我们可以选取一些可以凑出0 ...
- Netsh命令-修改网络IP设置
原文链接地址:https://blog.csdn.net/qq_38054198/article/details/77990914 静态设置IP 修改IP地址addr和子网掩码mask: \>n ...