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 4631: 踩气球 线段树合并
4631: 踩气球 Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 265 Solved: 136[Submit][Status][Discuss] ...
- 【bzoj2875】 Noi2012—随机数生成器
http://www.lydsy.com/JudgeOnline/problem.php?id=2875 (题目链接) 题意 求${X_{n}}$. Solution 矩乘板子,这里主要讲下会爆lon ...
- webpack进阶--打包
上一片博文主要让大家了解下究竟webpack是干什么的,明显它是专注于打包的. gulp 和 webpack 的区别 gulp,要求我们一步步写task(es6编译.css压缩.图片压缩.打包. ...
- Tomcat权威指南-读书摘要系列7
配置 conf目录下的主要配置文件 server.xml Tomcat主配置文件 web.xml servlet与其他适用于整个Web应用程序设置的配置文件,必须符合servlet规范的标准格式 to ...
- libvirt工具实现虚拟机管理
libvirt工具实现虚拟机管理 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.介绍virt-install命令的常用参数 virt-install是一个命令行工具,它能够为K ...
- *p++、(*p)++、*++p、++*p 的区别
int a[5]={1,2,3,4,5};int *p = a; *p++ 先取指针p指向的值(数组第一个元素1),再将指针p自增1: cout << *p++; // 结果为 1 cou ...
- linux下编译make文件报错“/bin/bash^M: 坏的解释器,使用grep快速定位代码位置
一.linux下编译make文件报错“/bin/bash^M: 坏的解释器 参考文章:http://blog.csdn.net/liuqiyao_01/article/details/41542101 ...
- 从ACM会议分析我国计算机科学近十年发展情况
从ACM会议分析我国计算机科学近十年发展情况 来源:<中国计算机学会通讯>2015年第10期<专栏> 作者:陈 钢 2006年,承蒙李国杰院士推荐,<中国计算机学会通讯& ...
- 8 Productivity hacks for Data Scientists & Business Analysts
8 Productivity hacks for Data Scientists & Business Analysts Introduction I was catching up with ...
- js 奇葩技巧之隐藏代码
昨天在群看到有人发了个文章叫<“短”化你的代码>,思路非常不错,采用unicode的零宽字符来实现字符隐藏,虽然有字符,可是你却看不见它.这篇文章详细的介绍了这种方法的实现原理,最后还给出 ...