HDU-1498-50years,50colors(最大匹配, 枚举)
链接:https://vjudge.net/problem/HDU-1498#author=634579757
题意:
撞气球游戏,一个n*n的矩阵中,有不同颜色的气球,气球的颜色最多50种(从1到50)。
游戏开始前,先选择一种颜色。游戏开始后,每次选择一行或者一列包含该种颜色的气球进行撞击。如果选择行,那么这一行的气球都会炸裂。如果选择列,这一列的气球都炸裂。
请你求出,有多少种颜色的气球,无论怎么玩,都不能在K次之内,把所有同色的气球都撞裂。
思路:
二分图匹配, 用set记录所有存在的颜色,然后根据x,y求最大匹配,条件是Map[i][j] == color。
最大匹配大于k即可。
代码:
#include <iostream>
#include <memory.h>
#include <string>
#include <istream>
#include <sstream>
#include <vector>
#include <stack>
#include <algorithm>
#include <map>
#include <queue>
#include <math.h>
#include <cstdio>
#include <set>
#include <iterator>
#include <cstring>
using namespace std; typedef long long LL;
const int MAXN = 2000+10;
vector<int> G[MAXN];
int Map[200][200];
int Link[MAXN], Vis[MAXN];
int n, m, k;
int mid; void Init()
{
for (int i = 1;i <= n;i++)
G[i].clear();
} bool Dfs(int x)
{
for (int i = 1;i <= n;i++)
{
if (Map[x][i] == mid && Vis[i] == 0)
{
Vis[i] = 1;
if (Link[i] == -1 || Dfs(Link[i]))
{
Link[i] = x;
return true;
}
}
}
return false;
} int Solve()
{
memset(Link, -1, sizeof(Link));
int cnt = 0;
for (int i = 1;i <= n;i++)
{
memset(Vis, 0, sizeof(Vis));
if (Dfs(i))
cnt++;
}
return cnt;
} int main()
{
while (~scanf("%d%d", &n, &m) && n)
{
set<int> node;
memset(Map, 0, sizeof(Map));
for (int i = 1;i <= n;i++)
{
for (int j = 1;j <= n;j++)
{
cin >> Map[i][j];
node.insert(Map[i][j]);
}
}
vector<int> Out;
for (set<int>::iterator it = node.begin();it != node.end();it++)
{
mid = *it;
int tmp = Solve();
if (tmp > m)
Out.push_back(mid);
}
if (!Out.size())
cout << -1 << endl;
else
{
cout << Out[0];
for (int i = 1;i < Out.size();i++)
cout << ' ' << Out[i];
cout << endl;
}
} return 0;
}
HDU-1498-50years,50colors(最大匹配, 枚举)的更多相关文章
- HDU 1281——棋盘游戏——————【最大匹配、枚举删点、邻接表方式】
棋盘游戏 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Status ...
- HDU 1498 50 years, 50 colors(最小点覆盖,坑称号)
50 years, 50 colors Problem Description On Octorber 21st, HDU 50-year-celebration, 50-color balloons ...
- HDU 1281 - 棋盘游戏 - [二分图最大匹配]
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=1281 Time Limit: 2000/1000 MS (Java/Others) Mem ...
- 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 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
- HDU 2819 ——Swap——————【最大匹配、利用linker数组、邻接表方式】
Swap Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Status ...
- HDU 1498:50 years, 50 colors(二分图匹配)
http://acm.hdu.edu.cn/showproblem.php?pid=1498 题意:给出一个 n*n 的矩阵,里面的数字代表一种颜色,每次能炸掉一排或者一列的相同颜色的气球,问有哪些颜 ...
- hdu 1498
每次只能消除一行或一列的相同颜色的气球, 求有多少种气球在k次内不能消除 求出每种气球最少需要多少次消除,就跟hdu 2119消除1用多少次是一样的问题 就是求有这种气球的行和列的最大匹配 #incl ...
- HDU 5752 Sqrt Bo【枚举,大水题】
Sqrt Bo Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total S ...
随机推荐
- matlab之结构体数组struct
以下内容来自于:https://blog.csdn.net/u010999396/article/details/54413615/ 要在MALTAB中实现比较复杂的编程,就不能不用struct类型. ...
- codeforces 622E E. Ants in Leaves(贪心+dfs)
题目链接: E. Ants in Leaves time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
- mac laravel 环境变量设置bash_profile
mac laravel 环境变量设置bash_profile >>>vim ~/.bash_profile '''text export PATH=$PATH:~/.composer ...
- 解决按 backspace键 出现 ^H 问题
输入命令 stty erase ^H #stty 时一个用来改变并打印终端行设置的常用命令stty iuclc # 在命令行下禁止输出大写stty -iuclc ...
- AtCoder Grand Contest #026 C - String Coloring
Time Limit: 3 sec / Memory Limit: 1024 MB Score : 600600 points Problem Statement You are given a st ...
- 简单两步快速实现shiro的配置和使用,包含登录验证、角色验证、权限验证以及shiro登录注销流程(基于spring的方式,使用maven构建)
前言: shiro因为其简单.可靠.实现方便而成为现在最常用的安全框架,那么这篇文章除了会用简洁明了的方式讲一下基于spring的shiro详细配置和登录注销功能使用之外,也会根据惯例在文章最后总结一 ...
- poj3784Running Median——堆维护中间值
题目:http://poj.org/problem?id=3784 将较小的数放入大根堆,较大的数放入小根堆,控制较小数堆大小比较大数堆小1,则较大数堆堆顶即为中位数. 代码如下: #include& ...
- UltraEdit注册机原理简单说明
UltraEdit注册机原理 By:大志若愚 UltraEdit 是 Windows 下一款流行的老牌文本/HEX 编辑器(非开源).UltraEdit 正被移植到 Linux 平台.该移植名为 UE ...
- matlab形态学图像处理之strel函数
转自:http://blog.sina.com.cn/s/blog_b1cd5d330101pmwi.html strel--structuring element 运用各种形状和大小构造元素,基本语 ...
- 搭建Node+NPM+Grunt+Ruby开发环境
序 最近尝试了一下CoffeeScript,和Sass,不得不说这两个搭配起来的确是不错的选择,熟悉以后基本上开发就比较快速了. 当然要开发这个首先需要搭建环境,这里就需要有Node.NPM.Grun ...