HDU 1498 50 years, 50 colors(最小点覆盖,坑称号)
50 years, 50 colors
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.
color of the ballon in the i row, j column.Input ends with n = k = 0.
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
-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(最小点覆盖,坑称号)的更多相关文章
- hdu 1498 50 years, 50 colors 最小点覆盖
50 years, 50 colors Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
- hdu1498 50 years, 50 colors --- 最小点覆盖
给一个矩阵,里面有一些不同颜色的气球.每次能够消灭一行或一列中某一种颜色的气球,问你在k次及以内,有哪些颜色的气球是不管怎样也消不完的. 那么思路就是,对每一种颜色的气球求最小点覆盖.>k 则为 ...
- HDU - 1054 Strategic Game(二分图最小点覆盖/树形dp)
d.一颗树,选最少的点覆盖所有边 s. 1.可以转成二分图的最小点覆盖来做.不过转换后要把匹配数除以2,这个待细看. 2.也可以用树形dp c.匈牙利算法(邻接表,用vector实现): /* 用ST ...
- hdu - 1150 Machine Schedule (二分图匹配最小点覆盖)
http://acm.hdu.edu.cn/showproblem.php?pid=1150 有两种机器,A机器有n种模式,B机器有m种模式,现在有k个任务需要执行,没切换一个任务机器就需要重启一次, ...
- 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 ...
- HDU——1498 50 years, 50 colors
50 years, 50 colors Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
- HDU 1498 50 years, 50 colors
题目大意:给你一个 n*n 的矩阵,每个格子上对应着相应颜色的气球,每次你可以选择一行或一列的同种颜色的气球进行踩破,问你在K次这样的操作后,哪些颜色的气球是不可能被踩破完的. 题解:对于每一种颜色建 ...
- hdu 1498(最小点覆盖集)
50 years, 50 colors Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
- 50 years, 50 colors
50 years, 50 colors Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
随机推荐
- Android 它们的定义View它BounceProgressBar
转载请注明出处:http://blog.csdn.net/bbld_/article/details/41246247 [Rocko's blog] 之前几天下载了非常久没用了的桌面版酷狗来用用的时候 ...
- Xcode6使用storyboard在TabBarController上建立三个以上Item
在Xcode5上做以上的操作没有问题,这次是要在Xcode6上实现之,特记录以备用. 首先新建一个storyboard文件.取名Custom.storyboard.拖动菜单添加一个TabBarComt ...
- 宽屏手机显示9.png的图片拉伸不均衡
制作的一个.9的背景图片,在一般的480宽的手机上显示没有问题,正常拉伸,用三星的一个宽屏手机测试时,没有完全拉伸,一边拉伸多一点,一边拉伸少一点 决绝办法:就是在制作.9的时候,我在横向拉伸的地方, ...
- 基于visual Studio2013解决C语言竞赛题之1016循环打印矩阵
题目 解决代码及点评 /* 找规律,编程序打印6×6的矩阵: 1 2 3 5 8 13 1 4 9 17 30 51 1 6 19 45 92 173 . . . */ ...
- Android 计时与倒计时
方法一 Timer与TimerTask(Java实现) [java] view plain copy print ? public class timerTask extends Activit ...
- SEO分享:我为什么会有这么多的优质外链资源?
前面小浪发了一篇文章" [完整版]我是怎样3个月把800指数的词做上首页的.",非常多人看了之后都表示非常佩服.顽强的运行力.确实SEO就是要顽强的运行力,也有人说吹牛吧,一天50 ...
- ios基础-编程规范
养成良好的编程习惯,是開始一门新语言的首要前提. (一)文档结构规范 1.建立Libs目录,存放第三方库 2.建立Tools目录,存放自己封装的类库 3.建立ViewControllers目录,存放全 ...
- 问题:Excel在“xxx.xlsx”中发现不可读取的内容。是否恢复此工作薄的内容?【原创】
现象: 点"是(Y)" 提示信息中提到的error242440_02.xml文件: 问题重现: package poi; import java.io.FileNotFoundEx ...
- 几种快速傅里叶变换(FFT)的C++实现
链接:http://blog.csdn.net/zwlforever/archive/2008/03/14/2183049.aspx一篇不错的FFT 文章,收藏一下. DFT的的正变换和反变换分别为( ...
- greatis很不错,出售源代码
http://www.greatis.com/delphicb/ 特别是: http://www.greatis.com/delphicb/imgedit/