题目大意:给你一个 n*n 的矩阵,每个格子上对应着相应颜色的气球,每次你可以选择一行或一列的同种颜色的气球进行踩破,问你在K次这样的操作后,哪些颜色的气球是不可能被踩破完的。

题解:对于每一种颜色建图,对于每一个点,要么横坐标被染色,要么纵坐标被染色,所以就是最小点覆盖。

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;
const int N=105;
int k,m,n;
int ans[55],link[N],used[N];
int map[N][N];
bool vis[N];
vector v[N];
bool Dfs(int k){
for(int i=0;i<v[k].size();i++){
int a=v[k][i];
if(used[a]==0){
used[a]=1;
if(link[a]==-1||Dfs(link[a])){link[a]=k;return 1;}
}
}return 0;
}
int main(){
while(scanf("%d%d",&n,&k),n!=0&&k!=0){
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)scanf("%d",&map[i][j]);
memset(vis,false,sizeof(vis));int cnt=0;
for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)
if(!vis[map[i][j]]){
vis[map[i][j]]=true;
for(int t=0;t<N;t++)v[t].clear();
for(int t=1;t<=n;t++)
for(int u=1;u<=n;u++)
if(map[t][u]==map[i][j])v[t].push_back(u);
int count=0; memset(link,-1,sizeof(link));
for(int u=1;u<=n;u++){
memset(used,0,sizeof(used));
if(Dfs(u))count++;
}
if(count>k)ans[cnt++]=map[i][j];
}
if(cnt==0)puts("-1");
else{
sort(ans,ans+cnt);
for(int i=0;i<cnt-1;i++)printf("%d ",ans[i]);
printf("%d\n",ans[cnt-1]);
}
}
return 0;
}

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. HDU——1498 50 years, 50 colors

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

  5. 50 years, 50 colors

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

  6. Hdu 1498 二分匹配

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

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

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

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

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

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

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

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

随机推荐

  1. Linux 文件内容转码

    文件内容的转换: iconv -f GB2312 -t UTF-8 gb1.txt >gb2.txt-f, –from-code=名称 原始文本编码-t, –to-code=名称 输出编码-o, ...

  2. 正整数从1到N,输出按照字典序排序的前K个数

    #include <iostream> #include <cassert> using namespace std; ; char a[max_len]; void topK ...

  3. LINQ to Entity Framework 操作符(转)

    在开始了解LINQ to Entities之前,需要先对.NET Framework 3.5版本后对C#语言的几个扩展特性做一些阐释,这有助于我们更容易.更深刻的理解LINQ to Entities技 ...

  4. Yii2.0中文开发向导——自定义日志文件写日志

    头部引入log类use yii\log\FileTarget; $time = microtime(true);$log = new FileTarget();$log->logFile = Y ...

  5. python 学习之Windows 下的编码处理!

    问题1: Non-ASCII character '\xe9' in file 问题原因:程序编码上出现问题 解决方法:在程序头部加上代码 #-*- coding: UTF-8 -*- 设置代码编码为 ...

  6. Python正则表达式指南(转载)

    转载自:http://www.cnblogs.com/huxi/archive/2010/07/04/1771073.html#3353540 1. 正则表达式基础 1.1. 简单介绍 正则表达式并不 ...

  7. 使用 http://httpbin.org/ 验证代理地址

    发现一个很方便的工具,在Linux 下使用  curl  http://httpbin.org/   可以返回当前使用的一些网络信息

  8. 实验时css层叠样式表不更新的情况

    自定义了CSS的样式,希望在页面中起作用.因为MVC中Views/Shared/_Layout.cshtml是所有视图的公共文件,如下: <!DOCTYPE html> <html& ...

  9. android 解决ViewPager双层嵌套的滑动问题

    解决ViewPager双层嵌套的滑动问题 今天我分享一下ViewPager的双层嵌套时影响内部ViewPager的触摸滑动问题 之前在做自己的一个项目的时候,遇到广告栏图片动态切换,我第一时间想到的就 ...

  10. VS2008发布程序

    下列附有VS2008发布程序介绍:vc2008程序发布指南2008-05-03 17:46vc2008开发的程序的发布方式可以有5种方式: 1. 采用静态链接到crt和MFC. 只要你拥有组成程序的所 ...