Antenna Placement
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 9586   Accepted: 4736

Description

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?

Input

On the first row of input is a single positive integer n, specifying the number of scenarios that follow. Each scenario begins with a row containing two positive integers h and w, with 1 <= h <= 40 and 0 < w <= 10. Thereafter is a matrix presented, describing
the points of interest in Sweden in the form of h lines, each containing w characters from the set ['*','o']. A '*'-character symbolises a point of interest, whereas a 'o'-character represents open space.

Output

For each scenario, output the minimum number of antennas necessary to cover all '*'-entries in the scenario's matrix, on a row of its own.

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

——————————————————————————————————
题目的意思是用1*2的矩形去覆盖*,可以重叠,问至少要多少个
思路:可以和别的不重叠覆盖的肯定一起覆盖,其他的单独覆盖。所以先将横纵坐标和为奇的和和为偶的进行二分图最大匹配再加上没匹配的
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <climits>
using namespace std; #define LL long long
const int INF = 0x3f3f3f3f;
const int MAXN=1005;
int uN,vN; //u,v数目
int g[MAXN][MAXN];
int linker[MAXN];
bool used[MAXN];
int link[MAXN];
int ha[MAXN][MAXN];
char s[MAXN];
int dir[4][2]= {{-1,0},{1,0},{0,-1},{0,1}}; bool dfs(int u)
{
int v;
for(v=0; v<vN; v++)
if(g[u][v]&&!used[v])
{
used[v]=true;
if(linker[v]==-1||dfs(linker[v]))
{
linker[v]=u;
return true;
}
}
return false;
} int hungary()
{
int res=0;
int u;
memset(linker,-1,sizeof(linker));
for(u=0; u<uN; u++)
{
memset(used,0,sizeof(used));
if(dfs(u)) res++;
}
return res;
} int main()
{
int m,n,k,x,y,T;
int q=1;
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&m);
int cnt=0;
memset(ha,-1,sizeof ha);
for(int i=0; i<n; i++)
{
scanf("%s",s);
for(int j=0; j<m; j++)
{
if(s[j]=='*')
ha[i][j]=cnt++;
}
}
memset(g,0,sizeof g);
for(int i=0; i<n; i++)
for(int j=0; j<m; j++)
if(ha[i][j]!=-1)
{
for(int k=0; k<4; k++)
{
int xx=i+dir[k][0];
int yy=j+dir[k][1];
if(xx>=0&&xx<n&&yy>=0&&yy<m&&ha[xx][yy]!=-1)
{
g[ha[i][j]][ha[xx][yy]]=1;
}
} }
uN=vN=cnt;
printf("%d\n",cnt-hungary()/2); }
return 0;
}

  

POJ3020 Antenna Placement的更多相关文章

  1. poj3020 Antenna Placement 匈牙利算法求最小覆盖=最大匹配数(自身对应自身情况下要对半) 小圈圈圈点

    /** 题目:poj3020 Antenna Placement 链接:http://poj.org/problem?id=3020 题意: 给一个由'*'或者'o'组成的n*m大小的图,你可以用一个 ...

  2. POJ3020 Antenna Placement —— 最大匹配 or 最小边覆盖

    题目链接:https://vjudge.net/problem/POJ-3020 Antenna Placement Time Limit: 1000MS   Memory Limit: 65536K ...

  3. POJ3020——Antenna Placement(二分图的最大匹配)

    Antenna Placement DescriptionThe Global Aerial Research Centre has been allotted the task of buildin ...

  4. POJ3020 Antenna Placement(二分图最小路径覆盖)

    The Global Aerial Research Centre has been allotted the task of building the fifth generation of mob ...

  5. POJ 3020 Antenna Placement

    Antenna Placement Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5645 Accepted: 2825 Des ...

  6. Antenna Placement(匈牙利算法 ,最少路径覆盖)

    Antenna Placement Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6991   Accepted: 3466 ...

  7. poj 3020 最短路径覆盖 Antenna Placement

    Antenna Placement Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7329   Accepted: 3635 ...

  8. Antenna Placement

    Antenna Placement Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7574 Accepted: 3762 Des ...

  9. poj 3020 Antenna Placement(最小路径覆盖 + 构图)

    http://poj.org/problem?id=3020 Antenna Placement Time Limit: 1000MS   Memory Limit: 65536K Total Sub ...

随机推荐

  1. c#networkcomms protobuf-net 文件加载出现问题

    服务器端里添加客户管理添加了些功能, 客户端私活连不上了,老程序没问题, 在服务器端程序里边也接受不到事件,客户端就提示链接中断了, 在客户端里边查了 链接中断是客户端上做的,当传回的包为0 事,程序 ...

  2. windbg 边学边记attach 进程和open dump的两个方式查看线程的占用cpu资源

    首先我是attach到进程的方式,附加到进程把. vs里边有个远程调试就是通过连接到远程机附加到进程操作的.在 有公网IP情况下挺好用,但涉及到nat穿越之类的,因为用户的不方便设置,这种调试方式也有 ...

  3. Unknown type name 'NSString' 解决方案

    今天看到个问题,编辑工程提示Unknown type name 'NSString',如下图 导致出现异常的原因是是因为工程中添加了ZipArchive(第三方开源解压缩库) 一般情况下出现“Unkn ...

  4. imaplib.error: command: SEARCH => got more than 10000 bytes

    imaplib.error: command: SEARCH => got more than 10000 bytes 使用IMAPLIB进行标记邮件状态的时候,在 typ,data=M.sea ...

  5. kafka的advertised.host.name参数 外网访问配置

    kafka的server.properties文件 ```host.name```开始只绑定在了内部IP上,对外网卡无法访问. 把值设置为空的话会kafka监听端口在所有的网卡上绑定.但是在外网访问时 ...

  6. openssl初步使用

    centos平台 md5.c #include <stdio.h> #include <string.h> #include <stdlib.h> //#inclu ...

  7. Linux下启动停止查看杀死Tomcat进程

    文章来自:http://www.linuxidc.com/Linux/2011-06/37180.htm 启动 一般是执行tomcat/bin/startup.sh,sh tomcat/bin/sta ...

  8. LCA(最近公共祖先)模板

    Tarjan版本 /* gyt Live up to every day */ #pragma comment(linker,"/STACK:1024000000,1024000000&qu ...

  9. dblink(转)

    oracle在进行跨库访问时,可以通过创建dblink实现,今天就简单的介绍下如果创建dblink,以及通过dblink完成插入.修改.删除等操作 首先了解下环境:在tnsnames.ora中配置两个 ...

  10. 2019.01.13 loj#6515. 贪玩蓝月(线段树分治+01背包)

    传送门 题意简述:有一个初始为空的双端队列,每次可以在队首和队尾插入或弹出一个二元组(wi,vi)(w_i,v_i)(wi​,vi​),支持询问从当前队列中选取若干个元素是的他们的和对 MODMODM ...