HDOJ 1498 —— 50 years, 50 colors 二分图匹配(最小点覆盖 = 最大二分匹配)
2014-11-16 17:20
363 查看
50 years, 50 colors
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1752 Accepted Submission(s): 962
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
题意:
给你一个矩阵,矩阵里面是气球,气球有1-50种颜色,问你在k次之内能不能把哪种存在的颜色消掉(每种颜色k次机会),不能消掉的颜色按升序输出。
需要知道:最小覆盖点 == 最大二分匹配
#include <stdio.h>
#include <string.h>
bool hs[110];//统计谁最后没办法在k步内全部踩爆
int mp[110][110];//读入矩阵
int flag[110];//匈牙利算法里面记录匹配的数组
bool vis[110];//匈牙利算法里面防止已经匹配的点再次匹配的标记数组
int step[110];//记录多少步能把这个颜色的所有气球踩爆
int n;//矩阵的阶数
int dfs(int u,int c)
{
for(int i = 1;i <= n;i++)
{
if(mp[u][i] == c && !vis[i])
{
vis[i] = true;
if(!flag[i] || dfs(flag[i],c))
{
flag[i] = u;
return 1;
}
}
}
return 0;
}
int main()
{
int k;
while(scanf("%d%d",&n,&k),n || k)
{
memset(mp,0,sizeof(mp));
memset(step,0,sizeof(step));
memset(hs,false,sizeof(hs));
for(int i = 1;i <= n;i++)
{
for(int j = 1;j <= n;j++)
scanf("%d",&mp[i][j]);
}
for(int i = 1;i <= 50;i++)
{
memset(flag,0,sizeof(flag));
for(int j = 1;j <= n;j++)
{
memset(vis,false,sizeof(vis));
step[i] += dfs(j,i);//统计全部踩爆的步数
}
}
int bj = 0;
for(int i = 1;i <= 50;i++)
{
if(step[i] > k)//如果全部踩爆的步数在给的步数之上
{
hs[i] = true;//标记下来k步内没办法踩爆的气球颜色编号
bj++;
}
}
if(!bj)
printf("-1\n");
else
{
int c = 0;
for(int i = 1;i <= 50;i++)
{
if(hs[i])
{
if(!c)
printf("%d",i);
else
printf(" %d",i);
c++;
}
}
printf("\n");
}
}
return 0;
}
相关文章推荐
- HDU 1498 50 years, 50 colors(二分最大匹配之最小点覆盖)
- hdu 1498 50 years, 50 colors(二分匹配,最小点覆盖)
- 杭电 1498 50 years, 50 colors【二分匹配+最小点覆盖问题】
- HDOJ 1498 - 50 years, 50 colors 水二分图..二分图最小点覆盖
- HDU1498_50 years, 50 colors(二分图/最小点覆盖=最大匹配)
- 【二分图匹配(最小顶点覆盖)】hdu 1498 50 years,50 colors
- hdu 1498 50 years, 50 colors(二分图匹配--最小点覆盖)
- HDU 1498 50 years, 50 colors (行列匹配+最小顶点覆盖)
- HDU 1498 50 years, 50 colors(匈牙利算法 二分最大匹配数)
- HDOJ 题目1498 50 years, 50 colors(最小点覆盖)
- HDOJ-----1498--50 years, 50 colors二分图(最小顶点覆盖)
- 50 years, 50 colors HDU - 1498(最小点覆盖或者说最小顶点匹配)
- HDU 1498 50 years, 50 colors (行列匹配+最小顶点覆盖)
- hdoj 1498 50 years, 50 colors (二分图--最小点覆盖)
- hdoj 1498 50 years, 50 colors 【最小点覆盖】
- hdu 1498 50 years, 50 colors (二分匹配)
- hdu 1498 50 years, 50 colors (二分匹配)
- hdu 1498 50 years, 50 colors(最小顶点覆盖)
- hdu 1498 50 years, 50 colors 二分图最大匹配
- HDU 1498 50 years, 50 colors(多次进行最小点覆盖运算)