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. [HRBUSTOJ1476]Pairs(FFT)

    题目链接:http://acm-software.hrbust.edu.cn/problem.php?id=1476 题意:给n个数,m次询问,每次询问一个k.问n个数里两数之和严格小于k的数对. 根 ...

  2. Linux链接库一(动态库,静态库,库放在什么路径下)

    http://www.cppblog.com/wolf/articles/74928.html http://www.cppblog.com/wolf/articles/77828.html http ...

  3. CUBRID学习笔记 31 通过select创建表

    语法 CREATE {TABLE | CLASS} <table_name> [( <column_definition> [,<table_constraint> ...

  4. ServiceStack.OrmLite 6 学习笔记 查

    查 根据id var result = db.SingleById<Poco>(1); 根据字段 var customer = db.Single<Customer>(new ...

  5. nancy中的诊断功能面板1

    nancyfx中有一项 诊断功能 ,可以查看网站的基本信息和其他相关信息,还包括查看会话信息,请求输出信息等. 假设你已经安装完了nancyfx.现在开始使用诊断功能: 一 安装 在你的Bootstr ...

  6. 线程入门之join方法

    package com.thread; /** * <join:将某线程加入进来,相当于方法调用,也叫合并某个线程> * <功能详细描述> * * @author 95Yang ...

  7. Linux基础01 学会使用命令帮助

    Linux基础01 学会使用命令帮助 概述 在linux终端,面对命令不知道怎么用,或不记得命令的拼写及参数时,我们需要求助于系统的帮助文档:linux系统内置的帮助文档很详细,通常能解决我们的问题, ...

  8. python_way ,json(自学)

    python_way ,json 如果我们想将多行字典存放到文件中,并且还需要调出这些字典继续使用那么就要是用json. 首先将字典用json转换成字符串,存放到文件中. a = {"tel ...

  9. XAF应用开发教程(四)应用程序模型

    XAF是重量型框架,确实够重量的,方方面面都做得规规矩矩. 如果看了前面三节,可能会认为,这N多的Attribute到底都是从哪里来的?到底有多少这样的Attribute?如果不够用了怎么办?等着官方 ...

  10. Linux配置apache等系列

    1.Linux下安装.配置PHP环境 2.ubuntu12.0.4安装apache, php ,mysql 3   CentOs中mysql的安装与配置