hdu 50 years, 50 colors(枚举点,最小点覆盖)

http://acm.hdu.edu.cn/showproblem.php?pid=1498

大致题意:给一个n*n的格子,每个格子中都放有不同颜色的气球。每次你可以选择一行或一列以及一种颜色的气球,然后将该行或该列上该种颜色的气球全部扎破。问经过K次,会有哪些气球是不可能被完全扎破的,按升序输出。

以行列为X,Y集合,对每一种颜色的气球构建二分图,求出二分图的最小点覆盖(最大匹配)m,即选取最少的点将所有的边覆盖。若m>k说明该颜色的气球不可能被完全扎破。

#include <stdio.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <string.h>
#include <queue>
#define LL long long
#define _LL __int64
using namespace std;
const int INF = 0x3f3f3f3f;
const int mod = 1000000007;
const int maxn = 110;

int n,k;
int Map[maxn][maxn];
int Map1[maxn][maxn];
int Max;
int res;
int match[10010],chk[10010];
vector <int> ans;

int dfs(int p)
{
	for(int i = 1; i <= n; i++)
	{
		if(!chk[i] && Map1[p][i])
		{
			chk[i] = 1;
			if(match[i] == -1 || dfs(match[i]))
			{
				match[i] = p;
				return 1;
			}
		}
	}
	return 0;
}

int main()
{
	while(~scanf("%d %d",&n,&k) && (n || k))
	{
		ans.clear();
		Max = 0;
		for(int i = 1; i <= n; i++)
		{
			for(int j = 1; j <= n; j++)
			{
				scanf("%d",&Map[i][j]);
				if(Max < Map[i][j])
					Max = Map[i][j];
			}
		}
		for(int col = 1; col <= Max; col++) //对每种颜色的气球建二分图
		{
			memset(Map1,0,sizeof(Map1));
			for(int i = 1; i <= n; i++)
			{
				for(int j = 1; j <= n; j++)
				{
					if(Map[i][j] == col)
						Map1[i][j] = 1;
				}
			}

			memset(match,-1,sizeof(match));
			res = 0;
			for(int i = 1; i <= n; i++)
			{
				memset(chk,0,sizeof(chk));
				res += dfs(i);
			}
			if(res > k)
				ans.push_back(col);
		}

		if(ans.size() == 0)
			printf("-1\n");
		else
		{
			sort(ans.begin(), ans.end());
			int len = ans.size();
			for(int i = 0; i < len-1; i++)
				printf("%d ",ans[i]);
			printf("%d\n",ans[len-1]);
		}

	}
	return 0;
}

hdu 50 years, 50 colors(枚举点,最小点覆盖)

时间: 2024-10-11 07:07:09

hdu 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/Others) Total Submission(s): 1635    Accepted Submission(s): 892 Problem Description On Octorber 21st, HDU 50-year-celebration, 50-color balloons floating

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

50 years, 50 colors Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) 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

HDU 1498 50 years, 50 colors(二分最大匹配之最小点覆盖)

题目地址:HDU 1498 晕啊...三个人同时做的这个题,结果全都理解错意思了..而且每个人理解错的地方还都不一样..但是样例还都能过,...简直炫酷... 题意:n*n的矩阵放置不同的颜色(不同的数字代表不同的颜色),你有k次选择,每一次只能选择某一行或某一列,可以消除该行(列)的所有颜色,问有哪几种颜色,无论怎样经过k次选择后依然无法完全抹去. 这个题的思路就是分别求出每种颜色的最少操作次数.然后只要大于k次的就是不符合要求的.然后输出就行了. #include <iostream> #

hdu 1498 50 years, 50 colors(最小顶点覆盖)

50 years, 50 colors Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1507    Accepted Submission(s): 811 Problem Description On Octorber 21st, HDU 50-year-celebration, 50-color balloons floating

HDU1498_50 years, 50 colors(二分图/最小点覆盖=最大匹配)

解题报告 题意: 给你一个矩阵,矩阵里面是气球,气球有1-50种颜色,问你在k次之内能不能把那种存在的颜色消掉(每种颜色k次机会),不能消掉的颜色按升序输出. 思路: 白想一上午了,理解错了题意,原来每种有k次可以消除的机会,还以为是总共k次机会消气球. 理解对了就很好做,类似POJ3041 求最小点覆盖.用最少的点覆盖最多的边. 每次枚举颜色看是否操作次数超过k次. 英语.................... ...................... #include <iostream

hdu149850 years, 50 colors (多个最小顶点覆盖)

50 years, 50 colors Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1516 Accepted Submission(s): 818 Problem Description On Octorber 21st, HDU 50-year-celebration, 50-color balloons floating aroun

hdu 1498 50 years, 50 colors 二分匹配

50 years, 50 colors Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1789    Accepted Submission(s): 978 Problem Description On Octorber 21st, HDU 50-year-celebration, 50-color balloons floating

hdu 1498 50 years, 50 colors

题目链接 1 #include <cstring> 2 #include <cstdio> 3 4 short G[101][101]; 5 bool vis[101]; 6 short match[101]; 7 short n; 8 9 bool dfs(short x, short c) 10 { 11 int i; 12 13 for(i=0;i<n;i++) 14 { 15 if(G[x][i] == c && !vis[i]){ 16 vis[i]

HDOJ 题目1498 50 years, 50 colors(最小点覆盖)

50 years, 50 colors Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1792    Accepted Submission(s): 981 Problem Description On Octorber 21st, HDU 50-year-celebration, 50-color balloons floating