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,501,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


//题意在刚接触的时候很难理解,和别人讨论过后才真正理解是什么意思。。。
//在给你一个n*n的矩阵之后,再给一个k代表你有几次机会,颜色相同的为一类气球,不同数字代表不同类气球
//对于描述中的最后一句话“ If there is no choice, print "-1". ”,有点不好理解,
//其实意思是对于每一类气球,你都有k次机会,如果在k次机会用完之后,看**哪一类的气球不能全部被弄破**
//然后把这些不能在k次机会全部弄破的气球的代表数字按照从小到大输出,如果每一类的气球都能在k次机会被弄破,
//那么则输出-1。 #include<queue>
#include<stack>
#include<vector>
#include<math.h>
#include<cstdio>
#include<sstream>
#include<numeric>//STL数值算法头文件
#include<stdlib.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<functional>//模板类头文件
using namespace std; const int INF=1e9+7;
const int maxn=510;
typedef long long ll; int n,k;
int map[maxn][maxn];//存放整个图 map[i][j]的值 就是该方格的颜色
int link[maxn];
int color[maxn],vis[maxn];//color[i]为真 表示i号颜色在整个map中出现 int dfs(int i,int co)//本次dfs过程中 是用 第i行 颜色为 co 去匹配,
{
for(int j = 0; j < n; j ++)
{
if(!vis[j] && map[i][j] == co)
{
vis[j] = 1;
if(link[j] == -1 || dfs(link[j],co))
{
link[j] = i;//把点的编号记录下来
return 1;
}
}
}
return 0;
} int KM(int co)
{
memset(link,-1,sizeof(link));//记录点的编号
int ans=0;
for(int i = 0; i < n ; i ++)
{
memset(vis,0,sizeof(vis));
if(dfs(i,co)) ans++;
}
return ans;
} int main()
{
int i,j;
int ans[51],tol;//ans[] 存放的是要输出的不能消灭的颜色号,tol表示不能消灭的颜色数量
while(scanf("%d%d",&n,&k),n+k)
{
memset(color,0,sizeof(color));
memset(map,0,sizeof(map));
for(i = 0; i < n; i ++)
{
for(j = 0; j < n; j ++)
{
scanf("%d",&map[i][j]);
color[map[i][j]] = 1;
}
}
tol=0;
for(i = 1; i <= 50; i ++)
{
if(color[i])//注意这里表示 i 号颜色是不是有的
{
if(KM(i) > k)//如果匹配最小消除i号颜色用到的次数大于k 意思就是不能消灭
ans[tol++]=i;
}
}
sort(ans,ans+tol);//注意排序
if(tol == 0)
printf("-1");
else
for(i = 0; i < tol; i ++)
i == 0 ? printf("%d",ans[i]):printf(" %d",ans[i]);//这里是简单的格式控制,两数据中有空格
printf("\n");
}
return 0;
}

50 years, 50 colors HDU - 1498(最小点覆盖或者说最小顶点匹配)的更多相关文章

  1. nyoj237 游戏高手的烦恼(最小点覆盖)

    题目237 题目信息 pid=237" style="text-decoration:none; color:rgb(55,119,188)">执行结果 本题排行 ...

  2. [poj] 3041 Asteroids || 最小点覆盖=最大二分图匹配

    原题 本题为最小点覆盖,而最小点覆盖=最大二分图匹配 //最小点覆盖:用最少的点(左右两边集合的点)让每条边都至少和其中一个点关联. #include<cstdio> #include&l ...

  3. 二分图变种之最小路径覆盖、最小点覆盖集【poj3041】【poj2060】

    [pixiv] https://www.pixiv.net/member_illust.php?mode=medium&illust_id=54859604 向大(hei)佬(e)势力学(di ...

  4. LA 2038 Strategic game(最小点覆盖,树形dp,二分匹配)

    题意即求一个最小顶点覆盖. 对于没有孤立点的图G=(V,E),最大独立集+最小顶点覆盖= V.(往最大独立集加点) 问题可以变成求树上的最大独立集合. 每个结点的选择和其父节点选不选有关, dp(u, ...

  5. Cogs 1632. 搬运工(二分图最小点覆盖)

    搬运工 ★ 输入文件:worker.in 输出文件:worker.out 简单对比 时间限制:1 s 内存限制:256 MB [题目描述] 小涵向小宇推荐了一款小游戏. 游戏是这样的,在一个n*n的地 ...

  6. Strategic game POJ - 1463 【最小点覆盖集】

    Bob enjoys playing computer games, especially strategic games, but sometimes he cannot find the solu ...

  7. 牛客 216D 消消乐 (二分图最小点覆盖)

    大意: 给定棋盘, 每次消除一行或一列, 求最小次数使得消除完所有'*'. 裸的二分图最小点覆盖. 二分图的最小点覆盖等于最大匹配, 输出方案时从所有左部未盖点开始标记交替路上的点, 最后左部所有未标 ...

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

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

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

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

随机推荐

  1. 【51NOD-0】1018 排序

    [算法]排序 #include<cstdio> #include<algorithm> using namespace std; ]; int main() { scanf(& ...

  2. 大聊Python----json与pickle数据序列化

    用于序列化的两个模块 ☆json,用于字符串和python数据类型间进行转换 ☆pickle,用于python特有的类型和python的数据类型间进行转换 Json模块提供了四个功能:dumps.du ...

  3. bufferd对象详解

    使用buffer类处理二进制数据 在客户端javascript脚本代码中,对于二进制数据并没有提供一个很好的支持.然后在nodejs中需要处理像TCP流或文件流时,必须要处理二进制数据.因此在node ...

  4. AndroidStudio 添加Selector文件,在res文件夹下添加文件夹

    在res文件夹下添加文件夹: 添加Selector文件:

  5. Part1-HttpClient快速入门案例

    前言 最近这段时间在学习爬虫方面的知识,接触了几个优秀的爬虫框架,也爬取了一些自己喜欢网站的信息.通过官网学习HttpClient的过程中,希望通过写此博客来巩固自己的学习,也为有需要的人提供学习帮助 ...

  6. 安装FFMpeg CentOS 7

    https://linuxadmin.io/install-ffmpeg-on-centos-7/

  7. C/C++中手动获取调用堆栈【转】

    转自:http://blog.csdn.net/kevinlynx/article/details/39269507 版权声明:本文为博主原创文章,未经博主允许不得转载. 当我们的程序core掉之后, ...

  8. skb管理函数之skb_clone、pskb_copy、skb_copy

    skb_clone--只复制skb描述符本身,如果只修改skb描述符则使用该函数克隆: pskb_copy--复制skb描述符+线性数据区域(包括skb_shared_info),如果需要修改描述符以 ...

  9. python基础===理解Class的一道题

    解题如下: from random import randint class Die(): def __init__(self,sides=6): self.sides = sides def rol ...

  10. 学习 Linux,101: 自定义或编写简单脚本【转】

    转自:http://www.ibm.com/developerworks/cn/linux/l-lpic1-105-2/index.html 学习如何使用标准的 shell 语法.循环和控制结构,以及 ...