http://acm.hdu.edu.cn/showproblem.php?pid=1498

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

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
LL   |   We have carefully selected several similar problems for you:  1528 1281 1151 1533 2063 
 
题意:给你一个n*n的矩阵,k次可以将每行或每列同颜色消去的操作,求一定不能消去的颜色,若没有输出-1;
n<=100;;;枚举每次想要消去的颜色,以同种颜色的格子的坐标构图,得出最大匹配。
 #include <algorithm>
#include <cstring>
#include <cstdio> const int N();
bool map[N][N],vis[N],linked[N];
int n,k,col[N][N],ans[N],match[N]; bool find(int u)
{
for(int v=;v<=n;v++)
if(map[u][v]&&!vis[v])
{
vis[v]=;
if(!match[v]||find(match[v]))
{
match[v]=u;
return true;
}
}
return false;
}
bool link()
{
int ret=;
for(int i=;i<=n;i++)
{
if(find(i)) ret++;
memset(vis,,sizeof(vis));
}
memset(match,,sizeof(match));
return ret>k;
} int main()
{
for(;scanf("%d%d",&n,&k)&&n&&k;)
{
int cnt=;
for(int i=;i<=n;i++)
for(int j=;j<=n;j++)
scanf("%d",&col[i][j]);
for(int i=;i<=n;i++)
for(int j=;j<=n;j++)
{
if(linked[col[i][j]]) continue;
linked[col[i][j]]=true;
for(int u=;u<=n;u++)
for(int v=;v<=n;v++)
if(col[u][v]==col[i][j])
map[u][v]=;
if(link()) ans[++cnt]=col[i][j];
memset(map,,sizeof(map));
}
memset(linked,,sizeof(linked));
if(!cnt) puts("-1");
else
{
std:: sort(ans+,ans+cnt+);
for(int i=;i<cnt;i++)
printf("%d ",ans[i]);
printf("%d\n",ans[cnt]);
}
memset(ans,,sizeof(ans));
}
return ;
}

HDU——T 1498 50 years, 50 colors的更多相关文章

  1. 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 ...

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

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

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

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

  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. 50 years, 50 colors HDU - 1498(最小点覆盖或者说最小顶点匹配)

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

  7. HDU 1498:50 years, 50 colors(二分图匹配)

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

  8. HDU 1498 50 years, 50 colors (行列匹配+最小顶点覆盖)

    题目:点击打开链接 题意:每个格子有不同颜色的气球用不同数字表示,每次可选某一行              或某一列来戳气球.每个人有K次机会.求最后哪些气球不能在             k次机会内 ...

  9. HDU 1498 50 years, 50 colors

    题目大意:给你一个 n*n 的矩阵,每个格子上对应着相应颜色的气球,每次你可以选择一行或一列的同种颜色的气球进行踩破,问你在K次这样的操作后,哪些颜色的气球是不可能被踩破完的. 题解:对于每一种颜色建 ...

随机推荐

  1. C#基础--索引器

    classProgram { staticvoidMain(string[] args) { man mm =new man(); mm[0]="jingya"; mm[1]=&q ...

  2. 数据库-mongodb有哪些命令工具

    MongoDB                  系统文件说明 1.mongo.exe              命令行客户端工具 2.mongod.exe            数据库服务程序 3. ...

  3. [Beginning SharePoint Designer 2010]Chapter2 编辑页面

    本章概要: 1.如何展开隐藏任务面板和ribbon标签 2.页面编辑模式 3.代码视图模式和智能提示 4.如何组合SharePoint和页面上其他元素

  4. HDU 4344

    其实不过是大整数分解... 注意两点:注意L 不能==N 但是,N却可以是素数...囧 #include <iostream> #include <cstdio> #inclu ...

  5. linux启动器文件(快捷方式)的制作方法

    众所周知.和windows不同,linux的软件安装方式是五花八门的= = 实用sh脚本写的,有tar包自己编译的.有rpm格式的,有deb的,有各种奇葩路径然后+chmod权限执行的.还有改各种配置 ...

  6. swift菜鸟入门视频教程-09-类和结构体

    本人自己录制的swift菜鸟入门,欢迎大家拍砖,有什么问题能够在这里留言. 主要内容: 类和结构体对照 结构体和枚举是值类型 类是引用类型 类和结构体的选择 集合(collection)类型的赋值与复 ...

  7. HTML5游戏实战之20行代码实现打地鼠

    之前写过一篇打地鼠的博客70行的代码实现打地鼠游戏,细致思考过后,发现70行代码都有点多余了,应用tangide的控件特性,能够将代码量缩减到20行左右. 先show一下终于成果,点击试玩:打地鼠.或 ...

  8. 智课雅思词汇---十三、前缀ab-是什么意思

    智课雅思词汇---十三.前缀ab-是什么意思 一.总结 一句话总结:分离,脱离;相反;加强意义 前缀:ab- [词根含义]:分离,脱离;相反;加强意义 [词根来源]:来源于拉丁语前缀ab-. [同源单 ...

  9. python 从bulkblacklist信誉查询网站提交查询

    import urllib import urllib2 #import webbrowser import re import socket def is_domain_in_black_list( ...

  10. notepad++ 插件推荐——快速定位文件

    介绍Notepad++的文章很多,我这里就不赘述了.简言之,是一个轻便的文本编辑工具.结合丰富的插件,可以实现很多功能,可以成为一个轻量级的IDE,用来做脚本开发非常合适. 这里介绍几个插件可以用来进 ...