50 years, 50 colors

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

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
 
Source
 
 
题目大意:
给你一个 n*n 的矩阵,每个格子上对应着相应颜色的气球,每次你可以选择一行或一列的同种颜色的气球进行踩破,问你在K次这样的操作后,哪些颜色的气球是不可能被踩破完的。
思路:
本题要求的是求出什么样的气球是根本就不可能被踩破的,而不是求的我们经过k次操作后剩下的气球的情况。
这样的话我们可以这样来考虑:现在我们一共有k次操作,也就是说对于每一种颜色的球,我们有k次机会都可以选择这一种颜色来把它全部清除。这样的话我们只需要判断我们在进行k次操作以后,我们当前选的颜色是否可以被完全清除就好了!
怎么判断?!我们仍然可以采用二分图来做,我们对于每一种颜色的球单独处理,将其横纵坐标看成两类,每一次只能选择一行或者是一列,这就跟上一个题是一样的了,然后进行二分图匹配,这样我们匹配出来的是我们可以用几次来将这种颜色的求全部消灭。
我们判断我们构建出来的图的最大匹配数是否大于k,若不是,那么说明我们可以将这种球消灭。反之,则不可以。记录。
代码:
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define N 110
using namespace std;
bool vis[N],vist[N];
int n,k,sum,tot,ans[N],girl[N],a[N][N],map[N][N];
int read()
{
    ,f=; char ch=getchar();
    ; ch=getchar();}
    +ch-'; ch=getchar();}
    return x*f;
}
int find(int x)
{
    ;i<=n;i++)
    {
        if(!vis[i]&&map[x][i])
        {
            vis[i]=true;
            ||find(girl[i])) {girl[i]=x; ;}
        }
    }
    ;
}
int col()
{
    ;
    memset(girl,-,sizeof(girl));
    ;i<=n;i++)
    {
        memset(vis,,sizeof(vis));
        if(find(i)) s++;
    }
    return s;
}
void begin()
{
    sum=,tot=;
    memset(a,,sizeof(a));
    memset(ans,,sizeof(ans));
    memset(vist,,sizeof(vist));
}
int main()
{
    )
    {
        n=read(),k=read();
        &&k==) break;
        begin();
        ;i<=n;i++)
         ;j<=n;j++)
          a[i][j]=read();
        ;i<=n;i++)
         ;j<=n;j++)
          if(!vist[a[i][j]])
          {
               vist[a[i][j]]=true;
               memset(map,,sizeof(map));
               ;u<=n;u++)
                ;v<=n;v++)
                 if(a[u][v]==a[i][j])
                  map[u][v]=;
               if(col()>k) ans[++sum]=a[i][j];
          }
       ) {printf("-1\n"); continue;}
       sort(ans+,ans++sum);
       ;i<sum;i++) printf("%d ",ans[i]);
       printf("%d\n",ans[sum]);
    }
    ;
}

HDU——1498 50 years, 50 colors的更多相关文章

  1. 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 ...

  2. HDU 1498 50 years, 50 colors(最小点覆盖,坑称号)

    50 years, 50 colors Problem Description On Octorber 21st, HDU 50-year-celebration, 50-color balloons ...

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

    50 years, 50 colors Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

  4. 50 years, 50 colors

    50 years, 50 colors Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...

  5. Hdu 1498 二分匹配

    50 years, 50 colors Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

  6. hdu 1498(最小点覆盖集)

    50 years, 50 colors Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

  7. HDU——T 1498 50 years, 50 colors

    http://acm.hdu.edu.cn/showproblem.php?pid=1498 Time Limit: 2000/1000 MS (Java/Others)    Memory Limi ...

  8. 50 years, 50 colors HDU - 1498(最小点覆盖或者说最小顶点匹配)

    On Octorber 21st, HDU 50-year-celebration, 50-color balloons floating around the campus, it's so nic ...

  9. HDU 1498:50 years, 50 colors(二分图匹配)

    http://acm.hdu.edu.cn/showproblem.php?pid=1498 题意:给出一个 n*n 的矩阵,里面的数字代表一种颜色,每次能炸掉一排或者一列的相同颜色的气球,问有哪些颜 ...

随机推荐

  1. shutil模块 + shelve模块 二合一版

    其他的看我前面的博客 import shutil # 将文件内容拷贝到另一个文件with open('old.xml','r') as read_f,open('new.xml', 'w') as w ...

  2. T4870 水灾(sliker.cpp/c/pas) 1000MS 64MB

    题目描述 大雨应经下了几天雨,却还是没有停的样子.土豪CCY刚从外地赚完1e元回来,知道不久除了自己别墅,其他的地方都将会被洪水淹没. CCY所在的城市可以用一个N*M(N,M<=50)的地图表 ...

  3. Selenium--Python环境部署

    本文引读:一二为python环境安装:三为selenium安装同时介绍了pip:四为PyCharm安装:五为验证SE可以正常使用 一.下载python安装包 我这里安装的是python3.6.5,官网 ...

  4. "码代码"微信号今日上线,为互联网同仁提供最前沿咨询

    "码代码"微信号今日上线 关注即有好礼相送 三月,春意浓浓的日子,三月,属于女人的日子,而今天...... “2014年天空成人放送大赏”于5日晚举办颁奖典礼,“年度最佳AV女优” ...

  5. 使用Jenkins进行android项目的自动构建(2)

    Maven and POM 1. 什么是Maven? 官方的解释是: http://maven.apache.org/guides/getting-started/index.html#What_is ...

  6. PostgreSQL执行机制的初步学习

    作为开源数据库的新手,近日有兴对比了Pg和MySQL的查询计划. 通过Pg源码目录下的src\backend\executor\README文件,加上一些简单调试,就能对Pg的执行机制产生一个初步印象 ...

  7. Winform webbrowser 隐藏 html 元素

    目的:用webbrowser打开网页,并隐藏网页上某个html元素 1.如果已知元素ID,比较好办 直接使用webbrowser1.Document.getElementById("id&q ...

  8. 模块 (Module)

    #1.模块概念的官网描述 -- Module If you quit from the Python interpreter and enter it again, the definitions y ...

  9. splice用法解析

    splice()方法算是最强大的数组方法了,它有很多种用法,主要用于删除指定位置的数组项,在指定的位置插入数组项,在指定位置替换数组项,slpice()方法始终都会返回一个数组,该数组包括从原始数组中 ...

  10. jstl笔记

    EL函数库 <%@page import="java.util.ArrayList"%> <%@ page language="java" c ...