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) ...
随机推荐
- c语言:union,大小端
union: 不允许只用联合变量名作赋值或其它操作. 也不允许对联合变量作初始化赋值,赋值只能在程序中进行. 小端存储: 以字节为单位,低存低,高存高. 任何数据在内存中都是以二进制(1或着0)顺序存 ...
- code blocks 快捷键
设置快捷键可以在setting-Editor-keyboard shortcuts里设置 ==日常编辑== • 按住Ctrl滚滚轮,代码的字体会随你心意变大变小.• 在编辑区按住右键可拖动代码,省去拉 ...
- urllib模块
python爬虫-urllib模块 urllib 模块是一个高级的 web 交流库,其核心功能就是模仿web浏览器等客户端,去请求相应的资源,并返回一个类文件对象.urllib 支持各种 web ...
- SpringMVC 返回字符串
今天看到一段代码,关于SpringMVC的Controller中返回字符串的代码,这段代码被我称为2b代码(英文名:2b Code). @RequestMapping(value="twoB ...
- HDU 3468 BFS+二分匹配
九野的博客,转载请注明出处 http://blog.csdn.net/acmmmm/article/details/10966383 开始建图打搓了,参考了大牛的题解打的版本比较清爽,后来改的基本雷同 ...
- 关于innodb purge thread和master thread
由innodb_purge_threads控制purge线程数. (>= 5.6.5)的版本号中该值默觉得1.最大值为32.默认值1表示innodb的purge操作被分离到purge线程中,ma ...
- 关于new enhancement的一些知识
关于new enhancement sap源程序里也给我们留了很多. 以下例句point .section.spot说明这些知识点. 1.不管是point还是section 都是基于spot的,spo ...
- NGUI: Documentation
Video Tutorials Basic Tutorial (v.2.5.0+) SD & HD atlas switching (advanced) Packed Font (advanc ...
- [LeetCode] Print All Combinations of a Number as a Sum of Candidate Numbers
题目连接:http://leetcode.com/2010/09/print-all-combinations-of-number-as-sum.html 题目分析: 由于这里说明了输入是升序的,当然 ...
- 基于visual Studio2013解决面试题之0302链表中找倒数k项节点
题目