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 的矩阵,里面的数字代表一种颜色,每次能炸掉一排或者一列的相同颜色的气球,问有哪些颜 ...
随机推荐
- WebService测试工具SoapUI
尊重原著作:本文转载自http://gqsunrise.iteye.com/blog/1958480 1. 简介 SoapUI是用java开发的测试web service的工具. 2. 安装 2.1. ...
- intellj idea 如何设置类头注释和方法注释
intellj idea 如何设置类头注释和方法注释 intellj idea的强大之处就不多说了,相信每个用过它的人都会体会到,但是我们也会被他的复杂搞的晕头转向,尤其刚从ecl ...
- isalpha函数,判断字符是否是字母
头文件:<iostream> or <cctype> 在c语言中<ctype.h> 功能:判断一个字符是否是英文字符,是大写返回1,是小写返回2,不是英文字符返 ...
- socket select模型
由于socket recv()方法是堵塞式的,当多个客户端连接服务器时,其中一个socket的recv调用时,会产生堵塞,使其他连接不能继续. 如果想改变这种一直等下去的焦急状态,可以多线程来实现(不 ...
- less 工具
less 工具也是对文件或其它输出进行分页显示的工具,应该说是linux正统查看文件内容的工具,功能极其强大.less 的用法比起 more 更加的有弹性.在 more 的时候,我们并没有办法向前面翻 ...
- 几年前无聊小游戏之作_WEB版本打泡泡
几年前写的小东西 主要是H5画布的操作,还有个C语言基于WIN SDK开发的版本 找不到代码了 找到了再分享 <!DOCTYPE html> <script src="ga ...
- Open开发平台,认证,授权,计费
1.申请appid和appkeyhttp://wiki.connect.qq.com/%E5%87%86%E5%A4%87%E5%B7%A5%E4%BD%9C_oauth2-0 appid:应用的唯一 ...
- SSE && WebSockets
SSE && WebSockets 参考 http://www.bitscn.com/school/HTMLCSS/201402/194940.html WebSockets 定义了一 ...
- 五年26个版本:Linux系统内核全程回顾
Phoronix.com今天将他们对Linux系统的研究发挥到了极致:从2005年年中的2.6.12,到正在开发中的2.6.37,五年多来的26个Linux内核版本来了个“群英荟萃”! 完成如此庞大规 ...
- iOS 相关职位要求整理版
在拉勾上找了20家,BOSS直聘找了10家感兴趣的在招聘 iOS 程序员的公司,把职位要求整理了一下. 初创公司一般要求1年以上开发经验,成长型或者成熟型公司一般要求最低2年以上开发经验.这里针对的是 ...