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. Tomcat设置欢迎页问题

    今天下载了tomat9,配置到eclipse后拉起来,想跑个欢迎页看看是否起好了,随手写了个index.jsp放到项目Struts2的WebContent根目录下,直接打开网页输入http://loc ...

  2. Volley的post使用

    直接看代码,注意在manifest中加入Internet权限 <uses-permission android:name="android.permission.INTERNET&qu ...

  3. Tair 分布式K-V存储方案

    tair 是淘宝的一个开源项目,它是一个分布式的key/value结构数据的解决方案. 作为一个分布式系统,Tair由一个中心控制节点(config server)和一系列的服务节点(data ser ...

  4. SpringMvc入门一----介绍

    Spring Mvc简介: Spring Web MVC是一种基于Java的实现了Web MVC设计模式的请求驱动类型的轻量级Web框架,即使用了MVC架构模式的思想,将web层进行职责解耦,基于请求 ...

  5. POJ_3740 Easy Finding ——精确覆盖问题,DLX模版

    Easy Finding Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 18790   Accepted: 5184 Des ...

  6. chrome浏览器,调试详解,调试js、调试php、调试ajax

    1.可以看到js报错 2.可以看到php报错 3.可以看到ajax返回的信息,以及报错情况 4.可以看到调用了那些内容以及顺序 5.可以调试js代码 6.可以查看session等等 功能非常之强大. ...

  7. 关于 NULL的坑

    有如下的表: select * from testtable where name in ('name'):  结果是第一条: select * from testtable where name n ...

  8. Vue 简单的总结一

    let 变量 1. 局部作用域 2. 不会存在变量提升 3. 变量不能重复声明 const 变量 1. 局部作用域 2. 不会存在变量提升 3. 变量不能重复声明 4. 只能声明常量,不可变得量 th ...

  9. LeetCode题解 #2 Add Two Numbers

    题目大意:使用链表表示的两个整数,计算出其和,以同样的形式返回. Input: (2 -> 4 -> 3) + (5 -> 6 -> 4) Output: 7 -> 0 ...

  10. 一.volatile关键字

    一.volatile关键字的原理 使用volatile关键字增加了实例变量在多个线程之间的可见性.但volatile的最致命的缺点是不支持原子性. synchronized代码块具有volatile同 ...