码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2014-08-15 14:45:00      阅读:239      评论:0      收藏:0      [点我收藏+]

标签:des   style   http   color   java   os   io   strong   

解题报告

题意:

给你一个矩阵,矩阵里面是气球,气球有1-50种颜色,问你在k次之内能不能把那种存在的颜色消掉(每种颜色k次机会),不能消掉的颜色按升序输出。

思路:

白想一上午了,理解错了题意,原来每种有k次可以消除的机会,还以为是总共k次机会消气球。

理解对了就很好做,类似POJ3041

求最小点覆盖。用最少的点覆盖最多的边。

每次枚举颜色看是否操作次数超过k次。

英语。。。。。。。。。。。。。。。。。。。。

。。。。。。。。。。。。。。。。。。。。。。

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;

int k,n,m,mmap[1100][1100],vis[1100],pre[1100],num[1100];
int dfs(int x,int c) {
    for(int i=1; i<=n; i++) {
        if(!vis[i]&&mmap[x][i]==c) {
            vis[i]=1;
            if(pre[i]==-1||dfs(pre[i],c)) {
                pre[i]=x;
                return 1;
            }
        }
    }
    return 0;
}
int main() {
    int i,j;
    while(~scanf("%d%d",&n,&k)) {
        memset(num,0,sizeof(num));
        if(!n&&!k)break;
        for(i=1; i<=n; i++)
            for(j=1; j<=n; j++)
                scanf("%d",&mmap[i][j]);
        int ans[100];
        for(int c=1; c<=50; c++) {
            memset(pre,-1,sizeof(pre));
            for(i=1; i<=n; i++) {
                memset(vis,0,sizeof(vis));
                num[c]+=dfs(i,c);
            }
        }
        int m=0,f=0;
        for(i=1; i<=51; i++) {
            if(num[i]&&num[i]>k) {
                ans[m++]=i;
                f=1;
            }
        }
        if(!f) {
            printf("-1\n");
            continue;
        }
        sort(ans,ans+m);
        for(i=0; i<m-1; i++) {
            printf("%d ",ans[i]);
        }
        printf("%d\n",ans[m-1]);
    }
}

50 years, 50 colors

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1607    Accepted Submission(s): 875


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.

bubuko.com,布布扣

 

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

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

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

标签:des   style   http   color   java   os   io   strong   

原文地址:http://blog.csdn.net/juncoder/article/details/38583459

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!