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. EntitySpace 常用语句

    EntitySpace 这个是很早期的ORM框架,最近发现这个破解的也都不能用了.有谁知道能用的,联系我. 1. where带几个条件的 query.Where(query.ProductTempSt ...

  2. 【转载】VS2013安装需要IE10

    因为需要移动办公,需要给笔记本搭建编程环境.安装VS2013时遇到了小麻烦,提示我,需要安装IE10. 然后我很听话的按照提供的超链接,到了官网,下载了最新的IE11,然后安装,结果告诉我下载的IE版 ...

  3. ios应用里面进入app store 下载界面

    转自:http://blog.csdn.net/diyagoanyhacker/article/details/6654838 在IOS应用里直接打开app store 评论页面的方法: [[UIAp ...

  4. 25、如何实现redis集群?

    由于Redis出众的性能,其在众多的移动互联网企业中得到广泛的应用.Redis在3.0版本前只支持单实例模式,虽然现在的服务器内存可以到100GB.200GB的规模,但是单实例模式限制了Redis没法 ...

  5. bzoj 1179 tarjan+spfa

    首先我们可以将这个图缩成DAG,那么问题中的路线就可以简化为DAG中的一条链,那么我们直接做一遍spfa就好了. 反思:开始写的bfs,结果bfs的时候没有更新最大值,而是直接赋的值,后来发现不能写b ...

  6. HTML语意化

    1.什么是HTML语义化? 根据内容的结构化(内容语义化),选择合适的标签(代码语义化)便于开发者阅读.写出更优雅的代码的同时让浏览器的爬虫和机器很好地解析.  2.为什么要语义化? 为了在没有CSS ...

  7. css控制文字换行

    1.word-wrap 设置为break-word时,文本中的长单词或url可以换行 <p style="width:100px;word-wrap:break-word;border ...

  8. Java的Integer常量池和String常量池

    1.Integer的常量池 看下面一段代码: package cn.qlq.test; public class ArrayTest { public static void main(String[ ...

  9. 安全测试===Web 安全渗透方面的学习路线

    作者:向生李链接:https://www.zhihu.com/question/21914899/answer/39344435来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明 ...

  10. [New learn] 设计模式思考

    本文是对上文[New learn] 设计模式的思考总结 1.大框架 无论应用使用多少种设计模式和技巧,此模式都是应用的大框架.下图为本项目的基本架构图: 1.上图中大框架为经典的MVC模式. 2.Co ...