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. Oracle_高级功能(5) 用户、角色、权限

    一.用户(模式)1.定义用户:对数据库的访问,需要以适当用户身份通过验证,并具有相关权限来完成一系列动作模式(schema):是某个用户所拥有的对象的集合.具有创建对象权限并创建了对象的用户称为拥有某 ...

  2. java 字符串截取类 区分中文、英文、数字、标点符号

    package com.founder.fix.ims; /** * @author WANGYUTAO * 操作字符串 */ public class SubString { // public s ...

  3. PCR技术

    qRT-PCR是指先由RNA进行反转录生成cDNA,然后以cDNA为模板进行检测,检测的是该cDNA的含量,而cDNA由特定的RNA逆转录而来,所以间接地检测了RNA的含量. 基因表达: 转录:DNA ...

  4. 多字节字符集与Unicode字符集

    在计算机中字符通常并不是保存为图像,每个字符都是使用一个编码来表示的,而每个字符究竟使用哪个编码代表,要取决于使用哪个字符集(charset). 多字节字符集: 在最初的时候,Internet上只有一 ...

  5. Codeforces 749D. Leaving Auction set+二分

    D. Leaving Auction time limit per test: 2 seconds memory limit per test:256 megabytes input:standard ...

  6. Spring 注解驱动(一)基本使用规则

    Spring 注解驱动(一)基本使用规则 Spring 系列目录(https://www.cnblogs.com/binarylei/p/10198698.html) 一.基本使用 @Configur ...

  7. Java设计模式(8)——策略模式

    一.策略模式定义 Strategy模式也叫策略模式是行为模式之一,它对一系列的算法加以封装,为所有算法定义一个抽象的算法接口,并通过继承该抽象算法接口对所有的算法加以封装和实现,具体的算法选择交由客户 ...

  8. Linux CPU Hotplug CPU热插拔

    http://blog.chinaunix.net/uid-15007890-id-106930.html   CPU hotplug Support in Linux(tm) Kernel Linu ...

  9. 2019.01.17 bzoj1853: [Scoi2010]幸运数字(容斥+dfs)

    传送门 搜索菜题,然而第一次没有注意然后爆longlonglong longlonglong了. 题意:称所有数位由6,86,86,8组成的数为幸运数字,问一个一个区间[l,r][l,r][l,r]中 ...

  10. 2018.12.17 ural1132 Square Root(二次剩余)

    传送门 MD写一道二次剩余的板题差点写自闭了. 我用的是cipollacipollacipolla算法. 利用的是欧拉准则来找寻一个二次非剩余类来求根. 注意这题有两个等根和模数为2的情况. 代码: ...