HDU 1498 50 years, 50 colors
题目大意:给你一个 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的更多相关文章
- 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 ...
- HDU 1498 50 years, 50 colors(最小点覆盖,坑称号)
50 years, 50 colors Problem Description On Octorber 21st, HDU 50-year-celebration, 50-color balloons ...
- hdu 1498 50 years, 50 colors 最小点覆盖
50 years, 50 colors Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
- HDU——1498 50 years, 50 colors
50 years, 50 colors Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
- 50 years, 50 colors
50 years, 50 colors Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- Hdu 1498 二分匹配
50 years, 50 colors Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
- hdu 1498(最小点覆盖集)
50 years, 50 colors Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
- 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 ...
- 50 years, 50 colors HDU - 1498(最小点覆盖或者说最小顶点匹配)
On Octorber 21st, HDU 50-year-celebration, 50-color balloons floating around the campus, it's so nic ...
- HDU 1498:50 years, 50 colors(二分图匹配)
http://acm.hdu.edu.cn/showproblem.php?pid=1498 题意:给出一个 n*n 的矩阵,里面的数字代表一种颜色,每次能炸掉一排或者一列的相同颜色的气球,问有哪些颜 ...
随机推荐
- Xposed出现 java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected implementation
Xposed出现 java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected implem ...
- Javascript知识三
O(∩_∩)O...今天继续学习了Javascript的知识,下面就总结一下. 数组: 判断是否为数组(instanceof Array) 在JavaScript中,数组不一定是同一类型 var ar ...
- IOS自学笔记1——学前准备
函数的声明和定义: 在标准的C编译器中,定义的函数只能调用前面已经定义的函数.若在main()函数里要调用其他方法,这时得首先在main()上面声明要调用的函数,即函数的声明. C语言中,函数的声明和 ...
- php功能---删除空目录
header('content-type:text/html;charset:utf-8'); function display($dir){ //判断是否是一个目录 if(!is_dir($dir) ...
- codeforces 540D 概率dp
传送门 大概可以这样理解, 一开始有r个石头, p个布, s个剪刀, 每一天有其中的两个相遇, 如果两个是相同的种类, 什么都不会发生, 否则的话有一个会挂掉, 问最后每一种生存的概率. dp[i][ ...
- 新浪sae 项目之 git 配置
新浪sae 项目现在支持git 配置了,但是有好多人配置不成功.下面对这个问题进行一个总结. 1. 在新浪云上面新建项目(该步骤省略) 2. 一般新建完毕后,会让你选择代码的管理工具,如下 注意这里, ...
- IOS 特定于设备的开发:使用加速能力“向上定位”
iPhone提供了3个机载的传感器,用于沿着iPhone的3根相互垂直的轴(左/右(x轴).上/下(y轴)和前/后(z轴))度量加速能力.这些值指示作用于iPhone的力,它们来自重力和用户移动.可以 ...
- nyoj 528 找球号(三)(哈希)
点解:题目链接 两种办法,1是使用容器set做 2必须知道这个结论, 突然感觉数论很强大啊,,,, /*//set容器处理 出一次加进去,再出现删掉,这个最后留下的就是那个只出现基数次的 #incl ...
- [转贴]JavaScript中Array(数组)的属性和方法
数组有四种定义的方式 使用构造函数:var a = new Array();var b = new Array(8); var c = new Array("first", &qu ...
- zombie-phantom
zombie-phantom zombie-phantom Provides a Zombie.js shim around the PhantomJS Headless Browser. npm i ...