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 ...
随机推荐
- Python学习之表的介绍
9.4 表的介绍 存储引擎 数据的存储方式就是存储引擎,引擎不同,数据的存储方式就不同 MySQL中比较重要的引擎: InnoDB:mysql5.6以上,默认的存储方式 支持 transactio ...
- python2.X与3.X比较及Python编译器选择
- 企业应用学习-git学习
1.git的基本使用 git与svn的区别 GIT 是分布式的,SVN 不是:这是 GIT 和其它非分布式的版本控制系统,例如 SVN,CVS 等,最核心的区别. GIT 把内容按元数据方式存储,而 ...
- 一本值得你反复研读的Python佳作《Python编程从0到1》
现在的Python入门书太多太多了,究竟如何选择呢? 当然选最好的最入门的讲解最清晰的,没有那么多废话的. 现在就推荐一本<Python编程从0到1>,还带视频的,到时候跟大家一起学习沟通 ...
- webpack的插件 http-webpack-plugin。 webpack-dev-server
自动的生成: bundle.js 和 index.html 在该项目的目录下:npm init -yes npm install vue -D npm install webpack@3.12.0 ...
- opencv滤镜-使用opencv实现各种图像滤镜特效
图像处理-滤镜 链接:https://mangoroom.cn/opencv/image-processing-filter.html opencv滤镜-实现晕影vignetting效果 链接:htt ...
- static 和extern关键字
static是C++中常用的修饰符,它被用来控制变量的存贮方式和可见性.extern "C"是使C++能够调用C写作的库文件的一个手段,如果要对编译器提示使用C的方式来处理函数的话 ...
- mysql(中)
mysql(中) 一.数据库配置 1.登录mysql 2.在mysql安装目录下:创建my.ini(my.cnf) 3.设置配置信息并保存 ''' [mysqld] character-set-ser ...
- 使用procedump捕获未处理异常的dump
-ma full memory dump, always do this on 2003 as 4gb is not much and it is good to have the heap -mp ...
- NSIS打包软件使用
NSIS打包软件使用 最近做的一个调用远程桌面的小应用需要打个安装包,并且在安装的时候需要添加注册表,我之前使用的都是"Advanced Installer"来打包应用程序的,这个 ...