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的代码注释
1.注释一块代码: %{ 此处代码块 %} 2.注释数行代码: 先选中,然后用组合键Ctrl+R 取消注释,用组合键Ctrl+T 3.双%%的作用:代码分块运行,点击双%%之间的代码,再点Run Se ...
- 使用libcurl,根据url下载对应html页面
1. [图片] Capture.JPG 2. [代码]GetPageByURL //static member variable definestring GetPageByURL::m_curPa ...
- centos6.3 安装python2.7.3
现在比较流行python2.7版本,centos6.3的默认版本是2.6.6,所以需要安装下2.7版本 1.下载安装python2.7 #wget http://www.python.org/ftp/ ...
- bzoj 4503 两个串 快速傅里叶变换FFT
题目大意: 给定两个\((length \leq 10^5)\)的字符串,问第二个串在第一个串中出现了多少次.并且第二个串中含有单字符通配符. 题解: 首先我们从kmp的角度去考虑 这道题从字符串数据 ...
- 【Lintcode】382.Triangle Count
题目: Given an array of integers, how many three numbers can be found in the array, so that we can bui ...
- visualVM远程监控JVM
对于完全没用使用过visualVM的初学者 环境:Windows PC上使用visualVM监控远端JVM @@@@jstatd方式连接@@@@ 1.Windows安装jdk,$JAVA_HOME/b ...
- /etc/bashrc和/etc/profile
在一般的 linux 或者 unix 系统中, 都可以通过编辑 bashrc 和 profile来设置用户的工作环境, 很多文章对于 profile 和 bashrc 也都有使用, 但究竟每个文件都有 ...
- 转学习LINUX的建议
作为一个新人,怎样学习嵌入式Linux?被问过太多次,特写这篇文章来回答一下.在学习嵌入式Linux之前,肯定要有C语言基础.汇编基础有没有无所谓(就那么几条汇编指令,用到了一看就会).C语言要学到什 ...
- Getting Started with OpenMP
Getting Started with OpenMP* Abstract As you probably know by now, to get the maximum performance be ...
- 【opencv学习笔记二】opencv3.4.0组件结构说明
在学习opencv使用之前我们先来看一下opencv有哪些组件结构.至于OpenCV组件结构的研究方法, 我们不妨管中窥豹,通过opencv安装路径下include目录里面头文件的分类存放,来一窥Op ...