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. JAVA帮助文档全系列 JDK1.5 JDK1.6 JDK1.7 官方中英完整版下载

    JAVA帮助文档全系列 JDK1.5 JDK1.6 JDK1.7 官方中英完整版下载JDK(Java Development Kit,Java开发包,Java开发工具)是一个写Java的applet和 ...

  2. Nmap使用指南(1)

    Nmap是一款开源免费的网络发现(Network Discovery)和安全审计(Security Auditing)工具.软件名字Nmap是Network Mapper的简称.Nmap最初是由Fyo ...

  3. 《FLASH CC 2015 CANVAS 中文教程》——1、导出canvas动画,文件结构浅析

    注::如果你对 FLASH 这个软件操作不够熟悉,建议你可以先看看FLASH动画之类的书. :FLASH CC 在文中直接简称为CC. :以下所以文章中所说的快捷键 如果你按了不起作用,请检查是否有其 ...

  4. iOS - UIToolbar

    前言 NS_CLASS_AVAILABLE_IOS(2_0) __TVOS_PROHIBITED @interface UIToolbar : UIView <UIBarPositioning& ...

  5. URLConnection 使用

    统一资源定位符URL(Uniform Resource Locator)是www客户机访问Internet时用来标识资源的名字和地址.超文本链路由统一资源定位符URL维持.URL的格式是: <M ...

  6. 手动导出Excel方法

    private void dgJiBingZhenDuanBind() {   Response.Clear(); Response.Charset = "GB2312"; Res ...

  7. linux 命令 第一波

    man 命令名字 查看命令详细解释 q退出cd 切换目录cd .. 回到上级目录su 切换用户pwd 当前目录mkdir cmy 创建cmy文件夹[目录]rm cmy 删除cmy文件夹[如果cmy里面 ...

  8. JavaScript变量——栈内存or堆内存

    原文  http://blog.csdn.net/xdd19910505/article/details/41900693 堆和栈这两个字我们已经接触多很多次,那么具体是什么存在栈中什么存在堆中呢?就 ...

  9. Android GestureDetector方法详解

    为了加强点击.拖动响应事件,Android提供了GestureDetector手势识别类.通过GestureDetector.OnGestureListener来获取当前被触发的操作手势(Single ...

  10. Css_2跟3

    #css2中的选择器 1.元素选择器     *通配符选择符.html类型选择符.id选择符.class选择符 2.关系选择器     E F(包含选择器).E>F(子选择器).E+F(E元素后 ...