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. UVA 12124 UVAlive 3971 Assemble(二分 + 贪心)

    先从中找出性能最好的那个数, 在用钱比較少的去组合,能组出来就表明答案在mid的右边,反之在左边, #include<string.h> #include<map> #incl ...

  2. 关于心理的二十五种倾向(查理&#183;芒格)-2

    5)避免不一致倾向避免不一致倾向实际上就是人天生就害怕改变.相同是由于人类大脑的生理机制决定的.由于这样的倾向能够带来节省运算空间和能量的优点.这样的抗改变模式的形成,可能的原因例如以下:A) 迅速作 ...

  3. python3连接Mairadb数据库

    <span style="font-size:18px;">#本代码演示的是python3.3.5下连接Mairadb数据库</span> <span ...

  4. 探索Android调用系统的分享功能

    非常多的应用为了应用的推广和传播都会使用"分享"的功能,点击分享button.就能将想要分享的内容或者图片分享至QQ空间.微博.微信朋友圈等实现了分享功能的应用.这篇文章主要是为了 ...

  5. 初识ecside

    ecside,基于jsp tag的开源列表组件.支持导出pdf.xsl.csv等文件. 主要标签<ec:table>\<ec:row>\<ec:column>. 支 ...

  6. 0x16 Trie

    这章刷的真带劲 嘿嘿 裸题 #include<cstdio> #include<iostream> #include<cstring> #include<cs ...

  7. Oracle多表连接效率,性能优化

    Oracle多表连接,提高效率,性能优化 (转) 执行路径:ORACLE的这个功能大大地提高了SQL的执行性能并节省了内存的使用:我们发现,单表数据的统计比多表统计的速度完全是两个概念.单表统计可能只 ...

  8. netty可靠性

    Netty的可靠性 首先,我们要从Netty的主要用途来分析它的可靠性,Netty目前的主流用法有三种: 1) 构建RPC调用的基础通信组件,提供跨节点的远程服务调用能力: 2) NIO通信框架,用于 ...

  9. WPF动态控件生成查找不到问题

    2012 08 10 遇到此类问题,已经找到解决方案 记录以备后用   动态往界面添加控件 在页面未显示的情况时,虽然对控件增加了id name等属性但是使用 TextBox txtOtherNati ...

  10. php 生成不重复的随机字符串

    md5(uniqid(md5(microtime(true)),true))