POJ-3020-Antena Placement(最小路径覆盖)
链接:
https://vjudge.net/problem/POJ-3020
题意:
The Global Aerial Research Centre has been allotted the task of building the fifth generation of mobile phone nets in Sweden. The most striking reason why they got the job, is their discovery of a new, highly noise resistant, antenna. It is called 4DAir, and comes in four types. Each type can only transmit and receive signals in a direction aligned with a (slightly skewed) latitudinal and longitudinal grid, because of the interacting electromagnetic field of the earth. The four types correspond to antennas operating in the directions north, west, south, and east, respectively. Below is an example picture of places of interest, depicted by twelve small rings, and nine 4DAir antennas depicted by ellipses covering them.
Obviously, it is desirable to use as few antennas as possible, but still provide coverage for each place of interest. We model the problem as follows: Let A be a rectangular matrix describing the surface of Sweden, where an entry of A either is a point of interest, which must be covered by at least one antenna, or empty space. Antennas can only be positioned at an entry in A. When an antenna is placed at row r and column c, this entry is considered covered, but also one of the neighbouring entries (c+1,r),(c,r+1),(c-1,r), or (c,r-1), is covered depending on the type chosen for this particular antenna. What is the least number of antennas for which there exists a placement in A such that all points of interest are covered?
思路:
对每个兴趣点标号,相邻的进行配对,再找最大匹配,答案则是总点数减去最大匹配一半。
因为是五向图,所有最大匹配是成功匹配的所有点数,除2正好是对数,而每一对只需一个就可以覆盖。
所有res = cnt-sum/2。
代码:
#include <iostream>
#include <cstdio>
#include <vector>
#include <memory.h>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <math.h>
using namespace std;
const int MAXN = 500;
const int INF = 1<<30;
int Next[4][2] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};
char Map[MAXN][MAXN];
int Dis[MAXN][MAXN];
vector<int> G[MAXN*MAXN];
int Linked[MAXN], Vis[MAXN];
int n, m, cnt;
bool Dfs(int x)
{
for (int i = 0;i < G[x].size();i++)
{
int node = G[x][i];
if (Vis[node])
continue;
Vis[node] = 1;
if (Linked[node] == -1 || Dfs(Linked[node]))
{
Linked[node] = x;
return true;
}
}
return false;
}
int Solve()
{
memset(Linked, -1, sizeof(Linked));
int sum = 0;
for (int i = 1;i <= cnt;i++)
{
memset(Vis, 0, sizeof(Vis));
if (Dfs(i))
sum++;
}
return sum;
}
int main()
{
int t;
scanf("%d", &t);
while (t--)
{
cnt = 0;
scanf("%d%d", &n, &m);
for (int i = 1;i <= n;i++)
scanf("%s", Map[i]+1);
for (int i = 1;i <= n;i++)
{
for (int j = 1;j <= m;j++)
if (Map[i][j] == '*')
Dis[i][j] = ++cnt;
}
for (int i = 1;i <= cnt;i++)
G[i].clear();
for (int i = 1;i <= n;i++)
{
for (int j = 1;j <= m;j++)
if (Map[i][j] == '*')
{
for (int k = 0;k < 4;k++)
{
int tx = i+Next[k][0];
int ty = j+Next[k][1];
if (tx < 1 || tx > n || ty < 1 || ty > m)
continue;
if (Map[tx][ty] == '*')
G[Dis[i][j]].push_back(Dis[tx][ty]);
}
}
}
int sum = Solve();
// cout << sum << endl;
cout << cnt-sum/2 << endl;
}
return 0;
}
POJ-3020-Antena Placement(最小路径覆盖)的更多相关文章
- poj 3020 Antenna Placement (最小路径覆盖)
链接:poj 3020 题意:一个矩形中,有n个城市'*'.'o'表示空地,如今这n个城市都要覆盖无线,若放置一个基站, 那么它至多能够覆盖本身和相邻的一个城市,求至少放置多少个基站才干使得全部的城市 ...
- POJ 2594 传递闭包的最小路径覆盖
Treasure Exploration Time Limit: 6000MS Memory Limit: 65536K Total Submissions: 7171 Accepted: 2 ...
- poj 2594 Treasure Exploration(最小路径覆盖+闭包传递)
http://poj.org/problem?id=2594 Treasure Exploration Time Limit: 6000MS Memory Limit: 65536K Total ...
- POJ 1548 Robots(最小路径覆盖)
POJ 1548 Robots 题目链接 题意:乍一看还以为是小白上那题dp,事实上不是,就是求一共几个机器人能够覆盖全部路径 思路:最小路径覆盖问题.一个点假设在还有一个点右下方,就建边.然后跑最小 ...
- POJ 1422 二分图(最小路径覆盖)
Air Raid Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 7278 Accepted: 4318 Descript ...
- POJ 1422 Air Raid (最小路径覆盖)
题意 给定一个有向图,在这个图上的某些点上放伞兵,可以使伞兵可以走到图上所有的点.且每个点只被一个伞兵走一次.问至少放多少伞兵. 思路 裸的最小路径覆盖. °最小路径覆盖 [路径覆盖]在一个有向图G( ...
- POJ 2594 (传递闭包 + 最小路径覆盖)
题目链接: POJ 2594 题目大意:给你 1~N 个点, M 条有向边.问你最少需要多少个机器人,让它们走完所有节点,不同的机器人可以走过同样的一条路,图保证为 DAG. 很明显是 最小可相交路径 ...
- POJ 1548 (二分图+最小路径覆盖)
题目链接:http://poj.org/problem?id=1548 题目大意:给出一张地图上的垃圾,以及一堆机器人.每个机器人可以从左->右,上->下.走完就废.问最少派出多少个机器人 ...
- poj 3020 Antenna Placement(最小路径覆盖 + 构图)
http://poj.org/problem?id=3020 Antenna Placement Time Limit: 1000MS Memory Limit: 65536K Total Sub ...
- POJ 3020 Antenna Placement【二分匹配——最小路径覆盖】
链接: http://poj.org/problem?id=3020 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22010#probl ...
随机推荐
- Tensorflow-gpu搭建CUDA 10.0与cuDNN等版本问题
https://blog.csdn.net/weixin_42718092/article/details/85001140
- Web前端学习书籍
<Head First HTML5 Programming> 介绍如何利用HTML5来搭建Web应用,包含JavaScript内容. <CSS禅意花园>: 不是入门的书籍,对C ...
- MySQL 数据库下载
地址链接: msi:https://dev.mysql.com/downloads/installer/ zip:https://downloads.mysql.com/archives/commun ...
- input type=file accept中文件格式限制
原文链接:https://blog.csdn.net/usuallyuser/article/details/83060341 accept="application/msexcel,app ...
- HDU 1176 免费馅饼 (动态规划、另类数塔)
免费馅饼 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- spring boot-14.集成MyBatis
1.如何使用注解版Mybatis? (1)引入mybatis ,druid,Mysql 的依赖,环境搭建可以参考第13篇的内容 <dependency> <groupId>or ...
- [转帖]linux /proc目录下的文件为何无法用vi编辑保存
linux /proc目录下的文件为何无法用vi编辑保存 https://blog.51cto.com/xlogin/1216914 学习一下 之前看过书 这一点 没太仔细看.. xlogin关注8人 ...
- Spring boot 整合 shiro 出现 org.apache.shiro.UnavailableSecurityManagerException: 错误
最开始参考的是这个 文档 但是并没有解决我的问题,因为他的配置和我的是一样(差不多)的 https://www.cnblogs.com/ginponson/p/6217057.html 然后看到此篇博 ...
- 安装VUE教程
这段时间公司要准备开始用VUE,安装的过程中就遇到各种奇葩问题 1.Node.js安装 https://nodejs.org/en/download/ 安装好noedeJS然后继续安装下一步 3.执行 ...
- Ubuntu下Win10虚拟机卡顿问题解决
问题描述 Ubuntu下用VMware创建了一个Windows10的虚拟机,初始给的配置如下: Memory: 4GB Graphics Memory: 1GB Hard Disk: 60GB 用的时 ...