# 50 years, 50 colors

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1695    Accepted Submission(s): 931

Problem Description
On
Octorber 21st, HDU 50-year-celebration, 50-color 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.

Input
There
will be multiple input cases.Each test case 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.

Output
For
each test case, print in ascending order all the colors of which are
impossible to be crashed by a student in k times. If there is no choice,
print "-1".

Sample Input
1 1
1
2 1
1 1
1 2
2 1
1 2
2 2
5 4
1 2 3 4 5
2 3 4 5 1
3 4 5 1 2
4 5 1 2 3
5 1 2 3 4
3 3
50 50 50
50 50 50
50 50 50
0 0

Sample Output
-1
1
2
1 2 3 4 5
-1

Author
8600

Source

Recommend

``` #include <cstdio>
#include <cstdlib>
#include <cstring>
const int maxn = ;
int ma[maxn][maxn];
int line[maxn],res[maxn];
bool vis[maxn],bj[maxn];
int k,n,m,t;
template <class T>
void init(T a){
memset(a,,sizeof(a));
}
int match(int st,int u)
{
for(int v = ;v<=n;v++)
{
if(ma[u][v]== st && !vis[v])
{
vis[v] = ;
if(line[v]==- || match(st,line[v]))
{
line[v] = u;
return ;
}
}
}
return ;
}
int cmp(const void *a,const void *b){
return *(int *)a - *(int *)b;
}
int K_M(int st)
{
memset(line,-,sizeof(line));
int ans = ;
for(int i = ;i<=n;i++){
init(vis);
ans += match(st,i);
}
return ans;
}
int main()
{
int t;
while(~scanf("%d%d",&n,&k))
{
if(n== && k== ) break;
init(ma); init(res); init(bj);
for(int i = ;i<=n;i++)
{
for(int j = ;j<=n;j++)
{
scanf("%d",&t);
ma[i][j] = t;
if(!bj[t])
bj[t] = ;
}
}
int cnt,num = ;
for(int i = ;i<=;i++)
{
if(bj[i]){
cnt = K_M(i);
(cnt>k)?(res[num++] = i):();
}
}
if(num==) puts("-1");
else{
qsort(res,num,sizeof(res[]),cmp);
for(int j = ;j<num-;j++)
printf("%d ",res[j]);
printf("%d\n",res[num-]);
}
}
return ;
}```

## hdu----149850 years, 50 colors(最小覆盖点)的更多相关文章

1. HDU 1498 50 years, 50 colors(最小点覆盖，坑称号)

50 years, 50 colors Problem Description On Octorber 21st, HDU 50-year-celebration, 50-color balloons ...

2. hdu 1498 50 years, 50 colors 最小点覆盖

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

3. hdu 1498 50 years, 50 colors（二分匹配_匈牙利算法）

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1498 50 years, 50 colors Time Limit: 2000/1000 MS (Ja ...

4. HDU——1498 50 years, 50 colors

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

5. 50 years, 50 colors

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

6. hdu149850 years, 50 colors (多个最小顶点覆盖)

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

7. 50 years, 50 colors HDU - 1498（最小点覆盖或者说最小顶点匹配）

On Octorber 21st, HDU 50-year-celebration, 50-color balloons floating around the campus, it's so nic ...

8. HDU——T 1498 50 years, 50 colors

http://acm.hdu.edu.cn/showproblem.php?pid=1498 Time Limit: 2000/1000 MS (Java/Others)    Memory Limi ...

9. HDU 1498：50 years, 50 colors（二分图匹配）

http://acm.hdu.edu.cn/showproblem.php?pid=1498 题意:给出一个 n*n 的矩阵,里面的数字代表一种颜色,每次能炸掉一排或者一列的相同颜色的气球,问有哪些颜 ...

## 随机推荐

1. Android Sqlite数据库相关——实现将 Sqlite 数据库复制到SD 卡

确定 sqlite 数据库所在位置(一般在data/data/com.pagename/databases/ 下,其中 com.pagename为当前项目包名) 确定 sqlite 数据库名称,拼接到 ...

2. 为 Node.js 开发者准备的 8 本免费在线电子书(转)

ode.js 是一套用来编写高性能网络服务器的JavaScript工具包,一系列的变化由此开始.比较独特的是,Node.js会假设你是在POSIX环境下运行它 Linux 或 Mac OS X.如果你 ...

3. Mercurial使用简单介绍【转】

Mercurial可以使异地开发进行统一的版本管理,比如一个项目有一部分人在银行内部开发无法用外网,另一部分人在公司开发,这两部分人需要一个统一的版本管理工具,mercurial这时候可以发挥作用 m ...

4. Uncaught TypeError: Object #&lt;Object&gt; has no method &#39;fancybox&#39;

Uncaught TypeError: Object #<Object> has no method 'fancybox' 2011-10-24 16:51:19|  分类: html|举 ...

5. 在Shell中使用函数文件

需要编写一个较庞大的脚本时,可能会涉及许多函数.变量.这是通常建议将众多的函数.变量放入一个单独的脚本内.这样做的好处很明显,不用担心某个函数.变量是否已经被定义和使用,也不用频繁地定义.清除函数和变 ...

6. Java中的Annotation(2)----Annotation工作原理

Java中的Annotation(2)----Annotation工作原理 分类: 编程语言2013-03-18 01:06 3280人阅读 评论(6) 收藏 举报 上一篇文章已经介绍了如何使用JDK ...

7. Struts的核心配置

一.配置struts.xml文件 1.struts.xml文件 2.常量配置 <constant> struts.properities web.xml中的<init-param&g ...

8. 在Windows上创建同样的Linux操作环境

在之前的文章中,介绍了我在GNU/Linux图形界面环境下所使用的工具集合.其基本目的是在保证占用最少系统资源的条件下,将电脑操作效率推向极致.这样的工具组合尤如瑞士军刀一般,简洁.高效.功能全面.与 ...

9. 网工的Linux系统学习历程

偶遇篇作为一名通过思科CCNP认证的网络工程师,专注于网络技术.但在日常的工作中,难免不接触到服务器,对于大多数服务器来说,鉴于稳定性等因素的考虑,基本使用的都是Linux系统,包括RHEL.Cent ...

10. TIMESTAMPDIFF用法

TIMESTAMPDIFF用法: TIMESTAMPDIFF(interval,datetime_expr1,datetime_expr2) 返回日期或日期时间表达式datetime_expr1 和d ...