POJ——T 3020 Antenna Placement
http://poj.org/problem?id=3020
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 9844 | Accepted: 4868 |
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 <cstring>
#include <cstdio> using namespace std; char s[];
int fx[]={,,,-};
int fy[]={,,-,};
bool vis[],map[][];
int cnt,match[],if_[][]; int find(int u)
{
for(int v=;v<=cnt;v++)
if(map[u][v]&&!vis[v])
{
vis[v]=;
if(!match[v]||find(match[v]))
{
match[v]=u;
return true;
}
}
return false;
} int main()
{
int t; scanf("%d",&t);
for(int n,m,ans=;t--;cnt=ans=)
{
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++)
{
scanf("%s",s+);
for(int j=;j<=m;j++)
if(s[j]=='*') if_[i][j]=++cnt;
}
for(int i=;i<=n;i++)
for(int j=;j<=m;j++)
if(if_[i][j])
for(int k=;k<;k++)
{
int x=i+fx[k],y=j+fy[k];
if(if_[x][y])
map[if_[i][j]][if_[x][y]]=;
}
for(int i=;i<=cnt;i++)
{
if(find(i)) ans++;
memset(vis,,sizeof(vis));
}
printf("%d\n",cnt-ans/);
memset(map,,sizeof(map));
memset(if_,,sizeof(if_));
memset(match,,sizeof(match));
}
return ;
}
POJ——T 3020 Antenna Placement的更多相关文章
- POJ 题目3020 Antenna Placement(二分图)
Antenna Placement Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7011 Accepted: 3478 ...
- (poj)3020 Antenna Placement 匹配
题目链接 : http://poj.org/problem?id=3020 Description The Global Aerial Research Centre has been allotte ...
- 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 Antenna Placement Time Limit: 1000MS Memory Limit: 65536K Total ...
- 二分图最大匹配(匈牙利算法) POJ 3020 Antenna Placement
题目传送门 /* 题意:*的点占据后能顺带占据四个方向的一个*,问最少要占据多少个 匈牙利算法:按坐标奇偶性把*分为两个集合,那么除了匹配的其中一方是顺带占据外,其他都要占据 */ #include ...
- POJ 3020 Antenna Placement【二分匹配——最小路径覆盖】
链接: http://poj.org/problem?id=3020 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22010#probl ...
- POJ 3020——Antenna Placement——————【 最小路径覆盖、奇偶性建图】
Antenna Placement Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u S ...
- POJ 3020 Antenna Placement
Antenna Placement Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5645 Accepted: 2825 Des ...
- POJ 3020 Antenna Placement 最大匹配
Antenna Placement Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6445 Accepted: 3182 ...
随机推荐
- HDU 1002 A + B Problem II( 高精度加法水 )
链接:传送门 题意:A + B 高精度,板子题 /************************************************************************* & ...
- vue通过路由实现页面刷新
vue 开发微信商城项目,需求如下: 购物车页面跳转到详情页,购物车页面包含了多个组件,点击结算跳转到订单页面,从订单返回时,购物车页面没有刷新,由于购物车组件之间通过bus实现事件传递,页面跳转(非 ...
- 读取bin文件,并且按结构体赋值打印
目标:读取一个bin文件,并且将bin文件中的数据,按字节对齐赋值给结构体,并且打印出结构体的内容 目前思路是简单的先将bin文件数据一次性读到一个数组中,再将数组强制转换为结构体 ] FILE *f ...
- MyBatis初始化
1. 准备工作 为了看清楚MyBatis的整个初始化过程,先创建一个简单的Java项目,目录结构如下图所示: 1.1 Product 产品实体类 public class Product { priv ...
- POJ 2183
模拟题 #include <iostream> #include <cstdio> #include <algorithm> using namespace std ...
- OS 中文斜体 Italic Font Chinese - iOS_Girl
CGAffineTransform matrix = CGAffineTransformMake(1, 0, tanf(15 * (CGFloat)M_PI / 180), 1, 0, 0); UI ...
- poj1961--Period(KMP求最小循环节)
Period Time Limit: 3000MS Memory Limit: 30000K Total Submissions: 13511 Accepted: 6368 Descripti ...
- nginx源代码分析--从源代码看nginx框架总结
nginx源代码总结: 1)代码中没有特别绕特别别扭的编码实现.从变量的定义调用函数的实现封装,都非常恰当.比方从函数命名或者变量命名就能够看出来定义的大体意义,函数的基本功能,再好的架构实如今编码习 ...
- Swift学习笔记(9):枚举
目录: 基本语法 关联值 原始值 枚举为一组相关的值定义了一个共同的类型. ・可以给枚举成员指定原始值类型:字符串,字符,整型值或浮点数等 ・枚举成员可以指定任意类型的关联值存储到枚举成员中 ・枚举可 ...
- .map(function(item)...)这个是按hashcode自动遍历的,怎么才能按照我想要的顺序遍历呢?
上图是我前端的遍历代码.我的item上有一个name的字段,分别是营业执照,税务登记证和经营许可证,我怎么设置才能让函数每次遍历的时候按照这个顺序遍历,而不是item自带的顺序呢? .map(func ...