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对男女 女生去选男朋友 如果女生从来没和那个男生吵架 那么那个男生就可以当她男朋友 女 ...
随机推荐
- 动画中的id与class使用css3的优先级问题
今天在做一个项目,用zepto给元素增加一个class,class里面有transform的效果.开始的时候,元素的样式是用id选择器写的,但是增加class之后,发现动画效果出不来,当时头好晕没想出 ...
- 第182天:HTML5——地理定位
HTML5 Geolocation(地理定位) HTML5 Geolocation API 用于获得用户的地理位置. 鉴于该特性可能侵犯用户的隐私,除非用户同意,否则用户位置信息是不可用的. 浏览器支 ...
- BZOJ4976 宝石镶嵌(动态规划)
显然被留下的宝石应该贡献至少一位,否则就可以扔掉.所以如果n-k>=logw,直接输出所有数的or.现在n变得和k同阶了.于是设f[i][j]为前i个数or为j时至少选几个数,转移显然.当然可以 ...
- BZOJ4896 THUSC2016补退选(trie)
字符串扔进trie,vector记录每个前缀出现次数的最大值的更新记录即可. #include<iostream> #include<cstdio> #include<c ...
- [CQOI2011]动态逆序对 CDQ分治
洛谷上有2道相同的题目(基本是完全相同的,输入输出格式略有不同) ---题面--- ---题面--- CDQ分治 首先由于删除是很不好处理的,所以我们把删除改为插入,然后输出的时候倒着输出即可 首先这 ...
- 【BZOJ3437】小P的牧场(动态规划,斜率优化)
[BZOJ3437]小P的牧场(动态规划,斜率优化) 题面 BZOJ 题解 考虑暴力\(dp\),设\(f[i]\)表示强制在\(i\)处建立控制站的并控制\([1..i]\)的最小代价. 很显然,枚 ...
- 【learning】01分数规划
问题描述 首先分数规划是一类决策性问题 一般形式是: \[ \lambda=\frac{f(x)}{g(x)} \] 其中\(f(x)\)和\(g(x)\)都是连续的实值函数,然后要求\(\lambd ...
- 【数论】数论进阶-Preknowledge
数论进阶-Preknowledge 参考资料:洛谷网校2018夏季省选基础班SX-3数论进阶课程及课件 一.整除与取整除法 1.1 定义 1.整除 \(\forall~x,y~\in~Z^+,\) 若 ...
- go的web框架beego
安装 beego 包含一些示例应用程序以帮您学习并使用 beego 应用框架. 您需要安装 Go 1.1+ 以确保所有功能的正常使用. 你需要安装或者升级 Beego 和 Bee 的开发工具: $ g ...
- Java配置jdk图文教程
1.计算机 ==>右键属性 2.高级系统设置 3.环境变量 4.找path变量 5.找到jdk的bin目录并复制路径到path环境变量里(jdk5.0以后就可以只配path路径了). 6.pat ...