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. Update与FixedUpdate区别

    以下的代码能使游戏暂停,记得要使速度*Time.deltaTime,目的是保证游戏运行在帧数不同的情况下,角色移动速度都一样,因为此时角色是按时间移动与帧数无关. using UnityEngine; ...

  2. XML学习笔记(二)-- DTD格式规范

    标签(空格分隔): 学习笔记 XML的一个主要目的是允许应用程序之间自由交换结构化的数据,因此要求XML文档具有一致的结构.业务逻辑和规则.可以定义一种模式来定义XML文档的结构,并借此验证XML文档 ...

  3. Python命令行解析argparse常用语法使用简介

    查看原文:http://www.sijitao.net/2000.html python中的命令行解析最简单最原始的方法是使用sys.argv来实现,更高级的可以使用argparse这个模块.argp ...

  4. Django.template框架 template context (非常详细)

    前面的章节我们看到如何在视图中返回HTML,但是HTML是硬编码在Python代码中的 这会导致几个问题: 1,显然,任何页面的改动会牵扯到Python代码的改动 网站的设计改动会比Python代码改 ...

  5. 构建一个简单的Maven项目

    这里用Maven Archetype插件从空白开始创建简单的项目. 熟悉Maven 项目和Maven的核心概念. 关键词:构建生命周期(build lifecycle), Maven仓库(reposi ...

  6. Python学习遇到的问题

    UnicodeDecodeError: 'gbk' codec can't decode byte 0xae in position

  7. poj 1556 (Dijkstra + Geometry 线段相交)

    链接:http://poj.org/problem?id=1556 The Doors Time Limit: 1000MS   Memory Limit: 10000K Total Submissi ...

  8. Mac : 强大的截图

    来源:http://irising.me/2011/11/12135/ Mac的截图功能扩展功能很强大的,不要用QQ那个COM+Ctrl+A弱爆了的截图了~ 首先说一下两种截图1.Command+sh ...

  9. SAP FI/CO凭证不一致的解决办法

    First, use program RKACOR20 to delete the incorrect CO documents. OKBA - Transfer FI Documents to CO ...

  10. eclipse查看jdk源码,及反编译查看

    jdk中的包: dt.jar是关于运行环境的类库,主要是swing的包 tools.jar是关于一些工具的类库 rt.jar包含了jdk的基础类库,也就是你在java doc里面看到的所有的类的cla ...