Antenna Placement POJ - 3020 (最小边集覆盖)
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 10699 | Accepted: 5265 |
Description
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?
Input
Output
Sample Input
2
7 9
ooo**oooo
**oo*ooo*
o*oo**o**
ooooooooo
*******oo
o*o*oo*oo
*******oo
10 1
*
*
*
o
*
*
*
*
*
*
Sample Output
17
5
Source
#include <iostream>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <algorithm>
#include <vector>
#define mem(a, b) memset(a, b, sizeof(a))
using namespace std;
const int maxn = , INF = 0x7fffffff;
int dx[maxn], dy[maxn], cx[maxn], cy[maxn], used[maxn];
int nx, ny, dis, n;
char str[][];
int gra[][];
vector<int> G[];
int dir[][] = {{,},{-,},{,},{,-}};
int bfs()
{
queue<int> Q;
dis = INF;
mem(dx, -);
mem(dy, -);
for(int i=; i<=nx; i++)
{
if(cx[i] == -)
{
Q.push(i);
dx[i] = ;
}
}
while(!Q.empty())
{
int u = Q.front(); Q.pop();
if(dx[u] > dis) break;
for(int v=; v<G[u].size(); v++)
{
int i=G[u][v];
if(dy[i] == -)
{
dy[i] = dx[u] + ;
if(cy[i] == -) dis = dy[i];
else
{
dx[cy[i]] = dy[i] + ;
Q.push(cy[i]);
}
}
}
}
return dis != INF;
} int dfs(int u)
{
for(int v=; v<G[u].size(); v++)
{
int i = G[u][v];
if(!used[i] && dy[i] == dx[u] + )
{
used[i] = ;
if(cy[i] != - && dis == dy[i]) continue;
if(cy[i] == - || dfs(cy[i]))
{
cy[i] = u;
cx[u] = i;
return ;
}
}
}
return ;
} int hk()
{
int res = ;
mem(cx, -);
mem(cy, -);
while(bfs())
{
mem(used, );
for(int i=; i<=nx; i++)
if(cx[i] == - && dfs(i))
res++;
}
return res;
} int main()
{
int T, kase = ;
cin>> T;
while(T--)
{
mem(gra, );
int ans = ;
for(int i=; i<maxn; i++) G[i].clear();
cin>> n;
for(int i=; i<n; i++)
{
cin>> str[i];
for(int j=; j<n; j++)
{
if(str[i][j] == '#')
gra[i][j] = ++ans; } }
for(int i=; i<n; i++)
{
for(int j=; j<n; j++)
{
if(str[i][j] == '#')
for(int k=; k<; k++)
{
int nx = i + dir[k][];
int ny = j + dir[k][];
if(str[nx][ny] == '#' && nx >= && ny >= && nx < n && ny < n)
G[gra[i][j]].push_back(gra[nx][ny]), G[gra[nx][ny]].push_back(gra[i][j]);
}
}
}
nx = ny = ans;
printf("Case %d: %d\n",++kase, hk()/);
} return ;
}
Antenna Placement POJ - 3020 (最小边集覆盖)的更多相关文章
- Antenna Placement POJ - 3020 二分图匹配 匈牙利 拆点建图 最小路径覆盖
题意:图没什么用 给出一个地图 地图上有 点 一次可以覆盖2个连续 的点( 左右 或者 上下表示连续)问最少几条边可以使得每个点都被覆盖 最小路径覆盖 最小路径覆盖=|G|-最大匹配数 ...
- (匹配 二维建图) Antenna Placement --POJ --3020
链接: http://poj.org/problem?id=3020 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82834#probl ...
- Antenna Placement poj 3020
Antenna Placement Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 12104 Accepted: 595 ...
- Antenna Placement poj 3020(匹配)
http://poj.org/problem?id=3020 题意:给定一个n*m的矩阵,'*'代表城市,现在想要用1*2的矩阵将所有的城市覆盖,问最少需要多少个矩阵? 分析:先为每个城市进行标号,再 ...
- (匹配)Antenna Placement --POJ --3020
链接: http://poj.org/problem?id=3020 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82834#probl ...
- POJ 3216 最小路径覆盖+floyd
Repairing Company Time Limit: 1000MS Memory Limit: 131072K Total Submissions: 6646 Accepted: 178 ...
- poj 1548(最小路径覆盖)
题目链接:http://poj.org/problem?id=1548 思路:最小路径覆盖是很容易想到的(本题就是求最小的路径条数覆盖所有的点),关键是如何建图,其实也不难想到,对于当前点,如果后面的 ...
- POJ3020 Antenna Placement —— 最大匹配 or 最小边覆盖
题目链接:https://vjudge.net/problem/POJ-3020 Antenna Placement Time Limit: 1000MS Memory Limit: 65536K ...
- poj 3216 (最小路径覆盖)
题意:有n个地方,m个任务,每个任务给出地点,开始的时间和完成需要的时间,问最少派多少工人去可以完成所有的任务.给出任意两点直接到达需要的时间,-1代表不能到达. 思路:很明显的最小路径覆盖问题,刚开 ...
随机推荐
- 4-51单片机ESP8266学习-AT指令(测试TCP服务器--使用串口调试助手--不连接路由器)
上一篇连接 http://www.cnblogs.com/yangfengwu/p/8757513.html 源码链接:https://pan.baidu.com/s/1wT8KAOIzvkOXXN ...
- C# WPF xml序列化 反序列化
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.W ...
- Tomcat 动态数据库连接池
package com.boguan.bte.util; import java.sql.Connection;import java.sql.SQLException;import java.uti ...
- WinDbg命令三部曲
WinDbg 命令三部曲:(一)WinDbg 命令手册 WinDbg 命令三部曲:(二)WinDbg SOS 扩展命令手册 WinDbg 命令三部曲:(三)WinDbg SOSEX 扩展命令手册
- CodeForces-1155D Beautiful Array
Description You are given an array \(a\) consisting of \(n\) integers. Beauty of array is the maximu ...
- 洛咕 P2336 [SCOI2012]喵星球上的点名
洛咕 P2336 [SCOI2012]喵星球上的点名 先求出SA和height,一个点名串对应的就是一段区间,还有很多个点,就转化成了 有很多个区间,很多个点集,对每个区间计算和多少个点集有交,对每个 ...
- JS计算混合字符串长度
用的是正则表达式 var str = ”坦克是tank的音译”; var len = str.match(/[^ -~]/g) == null ? str.length : str.length + ...
- Java 多线程(二)之 Thread 优先级
目录 Thread 中线程优先级相关属性 相关函数 优先级初始化 设置优先级 获取优先级 默认优先级 指定优先级 注意事项 优先级继承 @ Thread 中线程优先级相关属性 每个线程均有优先级,在 ...
- 【ORACLE】oracle数据库用户密码复杂度配置
-- 设置密码复杂度 SQL> @ /u01/app/oracle/product/11.2.0/db_1/rdbms/admin/utlpwdmg.sql -- 测试 SQL> alte ...
- 杂谈---LZ的编程之路以及十点建议
LZ本人是09年毕业的,在某二流本科院校学的非计算机专业,在兴趣的驱使之下,最终毅然决然的走上了编程这一条“不归路”. 说起LZ的经历虽不算是跌宕起伏,但也真正算是人生无常. 当初09年7月回到家里, ...