50 years, 50 colors HDU
和棋盘游戏一个类型的题目
矩阵转换为二分图最大匹配问题 每次碰撞气球都是一行或一列
#include<bits/stdc++.h>
using namespace std;
#define MAXI 105
int mp[MAXI][MAXI];
int used[MAXI];
int vis[MAXI];
int n,m;
int color[];
bool dfs(int x,int color)
{
for(int j=;j<=n;j++)
{
if(mp[x][j]==color&&!used[j])
{
used[j]=;
if(!vis[j]||dfs(vis[j],color))
{
vis[j]=x;
return true;
}
}
}
return false;
} int find1(int x)
{ int ans=;
memset(vis,,sizeof(vis));
for(int i=;i<=n;i++)
{
memset(used,,sizeof(used));
if(dfs(i,x))ans++;
}
return ans;
} int main()
{
int k;
while(scanf("%d%d",&n,&k)==&&(n||k))
{
int ans[MAXI];
memset(color,,sizeof(color));
memset(ans,,sizeof(ans)); for(int i=;i<=n;i++)
for(int j=;j<=n;j++)
{
scanf("%d",&mp[i][j]);
color[mp[i][j]]=;
} int n=;
for(int i=;i<=;i++)
{
if(color[i])
{
if(k<find1(i))
ans[n++]=i;
}
} sort(ans,ans+n); if(n==)printf("-1\n");
else
{
for(int i=;i<n-;i++)
printf("%d ",ans[i]);
printf("%d\n",ans[n-]);
} }
return ;
}
50 years, 50 colors HDU的更多相关文章
- 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(二分匹配_匈牙利算法)
题目链接: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 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) ...
- 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——T 1498 50 years, 50 colors
http://acm.hdu.edu.cn/showproblem.php?pid=1498 Time Limit: 2000/1000 MS (Java/Others) Memory Limi ...
- HDU 1498 50 years, 50 colors (行列匹配+最小顶点覆盖)
题目:点击打开链接 题意:每个格子有不同颜色的气球用不同数字表示,每次可选某一行 或某一列来戳气球.每个人有K次机会.求最后哪些气球不能在 k次机会内 ...
- HDU 1498:50 years, 50 colors(二分图匹配)
http://acm.hdu.edu.cn/showproblem.php?pid=1498 题意:给出一个 n*n 的矩阵,里面的数字代表一种颜色,每次能炸掉一排或者一列的相同颜色的气球,问有哪些颜 ...
- HDU 1498 50 years, 50 colors
题目大意:给你一个 n*n 的矩阵,每个格子上对应着相应颜色的气球,每次你可以选择一行或一列的同种颜色的气球进行踩破,问你在K次这样的操作后,哪些颜色的气球是不可能被踩破完的. 题解:对于每一种颜色建 ...
随机推荐
- BZOJ 4764: 弹飞大爷
4764: 弹飞大爷 Time Limit: 30 Sec Memory Limit: 256 MBSubmit: 4 Solved: 4[Submit][Status][Discuss] Des ...
- 【BZOJ1227】[SDOI2009]虔诚的墓主人(线段树)
[BZOJ1227][SDOI2009]虔诚的墓主人(线段树) 题面 BZOJ 洛谷 题解 显然发现答案就是对于每一个空位置,考虑上下左右各有多少棵树,然后就是这四个方向上树的数量中选\(K\)棵出来 ...
- mybatis的面试一对一,一对多,多对多的mapper.xml配置
使用springboot完成一对一,一对多: https://blog.csdn.net/KingBoyWorld/article/details/78966789 传统的mapper文件中的一对一, ...
- 集合框架基础知识-----java基础知识
Java集合框架 :接口:Collection.List .Set. Map:实现类:ArrayList.LinkedList.Vector.HashSet.TreeSet.HashMap.HashT ...
- 20181103 Nginx(布尔教育)
nginx介绍 对标Apache服务器 目录介绍 conf 配置文件 html 网页文件 logs 日志文件 sbin 主要二进制程序 控制命令 ./nginx # 启动 nginx -t # 测试配 ...
- C#实现物联网系统温度解析的函数(支持补码)
基于物联网协议上传数据,其中温度占两个字节,如01 27,表示温度值为29.7.温度负值为补码(也就是温度值为有符号数),例如0XFFFF值为负1(-0.1度). 针对补码要求,修改数据解析函数如下: ...
- bzoj千题计划261:bzoj3294: [Cqoi2011]放棋子
http://www.lydsy.com/JudgeOnline/problem.php?id=3294 如果一个颜色的棋子放在了第i行第j列,那这种颜色就会占据第i行第j列,其他颜色不能往这儿放 设 ...
- iOS 根据生日得到生肖,星座,年龄的算法
根据用户生日,得到相应的年龄,星座和生肖.有的项目中可能会用到,贴出来共享. 得到年龄,这个很简单了: - (void)getAgeWith:(NSDate*)birthday{ //日历 NSCal ...
- HDU 1431 素数回文 离线打表
题目描述:给定一个区间,将这个区间里所有既是素数又是回文数的数输出来. 题目分析:这题的这个数据范围比较大,达到了10^8级别,而且输入的数据有多组,又因为判断一个数是否是回文数貌似只有暴力判断,时间 ...
- 第10月第13天 xcode ipa
1. xcodebuild -exportArchive -exportFormat ipa -archivePath RongChatRoomDemo\ 17-7-13\ 下午4.04.xcarch ...