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
题意:一个n*m的平面内有一些点,有1*2的纸条,可以横放或竖放,求最少用多少张纸条才能覆盖所有点?
题解:纸条相当于一条边,上道题求得为覆盖所有边的最小点数,这道题则逆其道而行,可转化为覆盖所有点的最小边数,即最小路径覆盖
二分图中最小路径覆盖=点数-最小边覆盖
然后就可以用匈牙利跑了~
代码如下:
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std; vector<int> g[];
int vis[],link[];
int map[][],n,m,cnt,ttt;
char c[][]; int dfs(int x)
{
int sz=g[x].size();
for(int k=;k<sz;k++)
{
int y=g[x][k];
if(!vis[y])
{
vis[y]=;
if(!link[y]||dfs(link[y]))
{
link[y]=x;
return ;
}
}
}
return ;
} int search()
{
memset(link,,sizeof(link));
int tmp=;
for(int i=;i<=cnt;i++)
{
if(dfs(i))
{
memset(vis,,sizeof(vis));
tmp++;
}
}
return tmp;
} int main()
{
scanf("%d",&ttt);
while(ttt--)
{
cnt=;
scanf("%d%d",&n,&m);
memset(map,,sizeof(map));
for(int i=;i<=;i++)
{
g[i].clear();
}
for(int i=;i<=n;i++)
{
scanf("%s",c[i]);
for(int j=;j<m;j++)
{
if(c[i][j]=='o')
{
map[i][j+]=;
}
else
{
map[i][j+]=++cnt;
}
}
} for(int i=;i<=n;i++)
{
for(int j=;j<=m;j++)
{
if(map[i][j])
{
if(map[i][j+])
{
g[map[i][j]].push_back(map[i][j+]);
}
if(map[i][j-])
{
g[map[i][j]].push_back(map[i][j-]);
}
if(map[i+][j])
{
g[map[i][j]].push_back(map[i+][j]);
}
if(map[i-][j])
{
g[map[i][j]].push_back(map[i-][j]);
}
}
}
}
int ans=search();
int x=cnt-ans/;
printf("%d\n",x);
}
}

 

POJ3020 Antenna Placement(二分图最小路径覆盖)的更多相关文章

  1. POJ 3020 Antenna Placement (二分图最小路径覆盖)

    <题目链接> 题目大意:一个矩形中,有N个城市’*’,现在这n个城市都要覆盖无线,每放置一个基站,至多可以覆盖相邻的两个城市.问至少放置多少个基站才能使得所有的城市都覆盖无线? 解题分析: ...

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

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

  3. POJ 3020——Antenna Placement——————【 最小路径覆盖、奇偶性建图】

    Antenna Placement Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u S ...

  4. poj 3020 Antenna Placement (最小路径覆盖)

    二分图题目 当时看到网上有人的博客写着最小边覆盖,也有人写最小路径覆盖,我就有点方了,斌哥(kuangbin)的博客上只给了代码,没有解释,但是现在我还是明白了,这是个最小路径覆盖(因为我现在还不知道 ...

  5. [bzoj2150]部落战争_二分图最小路径覆盖

    部落战争 bzoj-2150 题目大意:题目链接. 注释:略. 想法: 显然是最小路径覆盖,我们知道:二分图最小路径覆盖等于节点总数-最大匹配. 所以我们用匈牙利或者dinic跑出最大匹配,然后用总结 ...

  6. Taxi Cab Scheme POJ - 2060 二分图最小路径覆盖

    Running a taxi station is not all that simple. Apart from the obvious demand for a centralised coord ...

  7. POJ3020Antenna Placement(最小路径覆盖+重在构图)

    Antenna Placement Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7788   Accepted: 3880 ...

  8. 【HDU3861 强连通分量缩点+二分图最小路径覆盖】

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3861 题目大意:一个有向图,让你按规则划分区域,要求划分的区域数最少. 规则如下:1.有边u到v以及有 ...

  9. hdu 1151 Air Raid(二分图最小路径覆盖)

    http://acm.hdu.edu.cn/showproblem.php?pid=1151 Air Raid Time Limit: 1000MS   Memory Limit: 10000K To ...

随机推荐

  1. oscache源码浅析

    oscache作为本地缓存框架,存储模型依然是通用的缓存键值对模型.oscache使用HashTable存放数据,我们看下源码: GeneralCacheAdministrator: /** * Ge ...

  2. spring mvc加了@produces注解后报406

    问题背景:调用http的post接口返回一个String类型的字符串时中文出现乱码,定位出问题后在@RequestMapping里加produces注解produces = "applica ...

  3. css中伪类和伪元素的区别

    转载:http://www.cnblogs.com/ihardcoder/p/5294927.html CSS3伪类和伪元素的特性和区别   前端er们大都或多或少地接触过CSS伪类和伪元素,比如最常 ...

  4. 【openCV学习笔记】【3】高斯模糊一张图片(_cvSmooth相关编译错误)

    代码如下: #include <iostream> #include <opencv/highgui.h> #include <opencv/cv.h> void ...

  5. C# 动态加载WebService

    项目中需要用到WebService的方式来进行两个服务之间的方法调用,之前都是在项目中添加服务引用的方式来实现,但是这种方式有一个弊端,就是如果提供WebService服务的一方的IP.端口一旦变更, ...

  6. 搭建httpd服务

    实验环境:CentOS7 实验步骤: 安装httpd服务:yum -y install httpd 关闭SELinux:setenforce 0 禁用防火墙策略:iptables -F 启动httpd ...

  7. HTTP 与TCP/IP 、Socket区别(一)

    网络由下往上分为: 物理层-- 数据链路层-- 网络层-- IP协议 传输层-- TCP协议 会话层-- 表示层和应用层-- HTTP协议 1.TCP/IP连接 手机能够使用联网功能是因为手机底层实现 ...

  8. js实现的点击div区域外隐藏div区域

    首先看下JS的事件模型,JS事件模型为向上冒泡,如onclick事件在某一DOM元素被触发后,事件将跟随节点向上传播,直到有click事件绑定在某一父节点上,如果没有将直至文档的根. 阻止冒泡:1.对 ...

  9. 5.solr学习速成之语法

    常用查询参数 q - 查询字符串,必须的.   fl - 指定返回那些字段内容,用逗号或空格分隔多个.  start - 返回第一条记录在完整找到结果中的偏移位置,0开始.   rows - 指定返回 ...

  10. 第九章 整合Mybatis(待续)

    ··········