50 years, 50 colors

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
 

有这样一个矩阵,矩阵里面是气球。气球有颜色编号1-50,询问在k次之内能不能把同种颜色存在的气球消掉(每次询问有K次机会),超过K此的气球编号,储存起来,并按编号按升序输出。

题意不是非常好理解,可是看明确之后,就非常清晰了

求最小点覆盖——即 用最少的点覆盖图中最多的边。

依次枚举就能够

矩阵的一维下标 当做 X集合,二维下标当做Y集合,询问全部点的最大匹配,比K大自然不满足

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <math.h>
#define init(a) memset(a,0,sizeof(a))
#define PI acos(-1,0)
using namespace std;
const int maxn = 110;
const int maxm = 100001;
#define lson left, m, id<<1
#define rson m+1, right, id<<1|1
#define min(a,b) (a>b)?b:a
#define max(a,b) (a>b)?a:b
const int N = 50010;
int ma[maxn][maxn];
int line[maxn],res[maxn];
bool vis[maxn],bj[maxn];
int k,n,m,t;
int cmp(const void *a,const void *b)
{
return *(int *)a - *(int *)b;
}
int DFS(int st,int u)
{
for(int v = 1;v<=n;v++)
{
if(ma[u][v]== st && !vis[v])
{
vis[v] = 1;
if(line[v]==-1 || DFS(st,line[v]))
{
line[v] = u;
return 1;
}
}
}
return 0;
}
int K_M(int st)
{
memset(line,-1,sizeof(line));
int ans = 0;
for(int i = 1;i<=n;i++)
{
init(vis);
ans += DFS(st,i);
}
return ans;
}
int main()
{
int t;
while(~scanf("%d%d",&n,&k))
{
if(n==0 && k== 0) break;
init(ma); init(res); init(bj);
for(int i = 1;i<=n;i++)
{
for(int j = 1;j<=n;j++)
{
scanf("%d",&t);
ma[i][j] = t;
if(!bj[t])
bj[t] = 1;
}
}
int cnt,num = 0;
for(int i = 1;i<=55;i++)
{
if(bj[i])
{
cnt = K_M(i);
(cnt>k)?(res[num++] = i):(1);
}
}
if(num==0) puts("-1");
else
{
//sort(res,res+num);
qsort(res,num,sizeof(res[0]),cmp);
for(int j = 0;j<num-1;j++)
printf("%d ",res[j]);
printf("%d\n",res[num-1]);
}
}
return 0;
}
 

HDU 1498 50 years, 50 colors(最小点覆盖,坑称号)的更多相关文章

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

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

  2. hdu1498 50 years, 50 colors --- 最小点覆盖

    给一个矩阵,里面有一些不同颜色的气球.每次能够消灭一行或一列中某一种颜色的气球,问你在k次及以内,有哪些颜色的气球是不管怎样也消不完的. 那么思路就是,对每一种颜色的气球求最小点覆盖.>k 则为 ...

  3. HDU - 1054 Strategic Game(二分图最小点覆盖/树形dp)

    d.一颗树,选最少的点覆盖所有边 s. 1.可以转成二分图的最小点覆盖来做.不过转换后要把匹配数除以2,这个待细看. 2.也可以用树形dp c.匈牙利算法(邻接表,用vector实现): /* 用ST ...

  4. hdu - 1150 Machine Schedule (二分图匹配最小点覆盖)

    http://acm.hdu.edu.cn/showproblem.php?pid=1150 有两种机器,A机器有n种模式,B机器有m种模式,现在有k个任务需要执行,没切换一个任务机器就需要重启一次, ...

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

  6. HDU——1498 50 years, 50 colors

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

  7. HDU 1498 50 years, 50 colors

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

  8. hdu 1498(最小点覆盖集)

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

  9. 50 years, 50 colors

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

随机推荐

  1. hdu 2546 饭卡 01背包

    先将前n-1个从小到大排序.对m-5进行01背包.然后答案就是m-dp[m-5]-a[n-1] 至于为什么最后减去最贵的菜品,而不是把最贵的菜品也放到01背包里呢, 由于假设能够把最贵菜品a[n-1] ...

  2. 基于JSP+SERVLET的新闻发布系统(二)

    接下来讲解的是通过AJAX验证用户名是否已经添加 用户名: <input type="text" name="userName" id="use ...

  3. delphi如何加上spliter分割条,任意调整大小

    如题1:如何把一个panel分割成四个小的panle 2:也就是如何加上spliter,分割条,任意调整大小 3.如何有独立的handle使用多个总共5个为什么呢,你放4个panel 然后放split ...

  4. 常见tcp端口

    TCP端口 7 = 回显 9 = 丢弃 11 = 在线用户 13 = 时间服务 15 = 网络状态 17 = 每日引用 18 = 消息发送 19 = 字符发生器 20 = ftp数据 21 = 文件传 ...

  5. Redhat下安装fedora

    步骤具体解释: 1:到fedora官网下载fedora的DVD镜像文件. 2:在linux系统中预留一部分为未分区的空间大约50G 3:   在linux系统上的根分区创建一个fedora的目录,里面 ...

  6. 【图像处理】Gabor过滤器

    Gabor内核参考wiki 使用实数Real的公式计算核函数代码: Mat getGaborFilter(float lambda, float theta, float sigma2,float g ...

  7. mysql的1067错误 - 2

    上一篇博文<mysql的1067错误>中由于日志配置问题产生1067错误. 由于要升级MySQL到V5.6,所以拷贝my.ini和数据文件到新的系统上. 在启动服务时,又出现1067错误! ...

  8. 时间戳timestamp

    1 时间戳 数据库中自动生成的 唯一的 二进制的数据,通常用作给数据表的行添加版本戳的机制. timestamp与时间和日期无关. timestamp存储大小为8字节. 一个数据表只能有一个times ...

  9. 矩形、占位符组件——axure线框图部件库介绍

    矩形组件和占位符没有太多的区别,这里我们主要讲解矩形组件的操作和使用,占位符的操作各位可以按照矩形的操作方法进行练习一下. 矩形组件是一个矩形,它可以用来做很多的工作,比如页面上需要一块蓝色的背景,就 ...

  10. Maven 实现Struts2注解配置步骤详解

    1,pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www ...