链接: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(最大匹配, 枚举)的更多相关文章

  1. HDU 1281——棋盘游戏——————【最大匹配、枚举删点、邻接表方式】

     棋盘游戏 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status ...

  2. HDU 1498 50 years, 50 colors(最小点覆盖,坑称号)

    50 years, 50 colors Problem Description On Octorber 21st, HDU 50-year-celebration, 50-color balloons ...

  3. HDU 1281 - 棋盘游戏 - [二分图最大匹配]

    题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=1281 Time Limit: 2000/1000 MS (Java/Others) Mem ...

  4. 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 ...

  5. hdu 1498(最小点覆盖集)

    50 years, 50 colors Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

  6. HDU 2819 ——Swap——————【最大匹配、利用linker数组、邻接表方式】

     Swap Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status ...

  7. HDU 1498:50 years, 50 colors(二分图匹配)

    http://acm.hdu.edu.cn/showproblem.php?pid=1498 题意:给出一个 n*n 的矩阵,里面的数字代表一种颜色,每次能炸掉一排或者一列的相同颜色的气球,问有哪些颜 ...

  8. hdu 1498

    每次只能消除一行或一列的相同颜色的气球, 求有多少种气球在k次内不能消除 求出每种气球最少需要多少次消除,就跟hdu 2119消除1用多少次是一样的问题 就是求有这种气球的行和列的最大匹配 #incl ...

  9. HDU 5752 Sqrt Bo【枚举,大水题】

    Sqrt Bo Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total S ...

随机推荐

  1. Zookeeper原理与Curator使用

    近期打算实现一个基于Zookeeper的分布式的集群状态一致性控制, 对Zookeeper的原理不太了解, 正好学习一下, 网上找到了几篇文章, 先贴在这边, 等我熟读官方文档后, 再来补充自己的见解 ...

  2. JavaScript--Object类

    Object类是所有JavaScript类的基类,提供了一种创建自定义对象的简单方式,不需要程序员再定义构造函数. 主要属性: constructor-对象的构造函数 prototype-获得类的pr ...

  3. html5--1.19 通用属性

    html5--1.19 通用属性 学习要点: 1.通用属性的概念及几个常用的通用属性2.对属性值的若干点补充 通用属性 通用属性(全局属性)可以用于任何的HTML5元素:通用属性有十几种:这节课不会全 ...

  4. 基于深度学习的目标检测算法:SSD——常见的目标检测算法

    from:https://blog.csdn.net/u013989576/article/details/73439202 问题引入: 目前,常见的目标检测算法,如Faster R-CNN,存在着速 ...

  5. 洛谷P1020导弹拦截——LIS

    题目:https://www.luogu.org/problemnew/show/P1020 主要是第二问,使用了dilworth定理:一个序列中最长不上升子序列的最大覆盖=最长上升子序列长度. di ...

  6. Unix Timestamp

    class Foundation_API DateTime /// This class represents an instant in time, expressed /// in years, ...

  7. SVN服务器搭建教程

    常见的源代码管理工具 CVS 历史悠久,现在几乎没人使用 SVN 集中式版本控制的代表 CVS的接班人,速度比CVS快,功能比CVS强大 在国内使用率非常高(70%~90%) GIT 分布式源代码管理 ...

  8. libvirtError: 无效参数:could not find capabilities for domaintype=kvm

    libvirtError: 无效参数:could not find capabilities for domaintype=kvm 编辑/etc/nova/nova.conf 在[libvirt] 添 ...

  9. Javascript Tip(!!)

    var a:var b=!!a; a默认是undefined.!a是true,!!a则是false,所以b的值是false,而不再是undefined,也非其它值,主要是为后续判断提供便利. !!一般 ...

  10. linux工具————fish shell

    1.说明 fish is a fully-equipped command line shell (like bash or zsh) that is smart and user-friendly. ...