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 大意:方格地图上有一些点用 '*' 表示,一个椭圆可以覆盖两个相邻的点(上下左右),问最少用多少椭圆能覆盖所有点 解法:每个 '*' 拆为两个点,能够同时覆盖的点连边,构成二分图,跑一边匹配。
要使用的椭圆数='*'总数 - 匹配数 + floor(匹配数/2)
原因:匹配数/2为 要求每个椭圆覆盖两个'*'时 能够使用的最大椭圆数。
这样覆盖后还剩下(总数 - 匹配数)个'*',对于每个剩下的'*',只能再使用一个椭圆。 提交三次
第一次选错编译器,第二次邻接表没有清空
第三次
 #include<iostream>
#include<cstdio>
#include<cstring>
#include<ctime>
#include<cstdlib>
#include<algorithm>
#include<cmath>
using namespace std;
int read(){
int xx=,ff=;char ch=getchar();
while(ch>''||ch<''){if(ch=='-')ff=-;ch=getchar();}
while(ch>=''&&ch<=''){xx=(xx<<)+(xx<<)+ch-'';ch=getchar();}
return xx*ff;
}
const int ws_[]={-,,,},ad_[]={,,,-};
int H,W,T,id[][],tx,ty,sum,ans;
char mp[][];
int lin[],len;
struct edge{
int next,y;
}e[];
inline void insert(int xx,int yy){
e[++len].next=lin[xx];
lin[xx]=len;
e[len].y=yy;
}
int vis[],tim,pretim,match[];
bool hun(int x){
for(int i=lin[x];i;i=e[i].next)
if(vis[e[i].y]<=pretim){
vis[e[i].y]=++tim;
if(match[e[i].y]==||hun(match[e[i].y])){
match[e[i].y]=x;
match[x]=e[i].y;
return ;
}
}
return ;
}
int main(){
//freopen("in","r",stdin);
//freopen("out","w",stdout);
T=read();
while(T--){
H=read(),W=read();
for(int i=;i<=H;i++){
for(int j=;j<=W;j++)
mp[i][j]=getchar(),id[i][j]=(i-)*W+j;
getchar();
}
len=;
memset(lin,,sizeof(lin));
for(int i=;i<=H;i++)
for(int j=;j<=W;j++)
if(mp[i][j]=='*')
for(int k=;k<;k++){
tx=i+ws_[k],ty=j+ad_[k];
if(tx<=||tx>H||ty<=||ty>W)
continue;
if(mp[tx][ty]=='*')
insert(id[i][j],id[tx][ty]+H*W);
}
tim=;sum=;ans=;
memset(vis,,sizeof(vis));
memset(match,,sizeof(match));
for(int i=;i<=H;i++)
for(int j=;j<=W;j++)
if(mp[i][j]=='*'){
sum++;
pretim=tim;
vis[id[i][j]]=++tim;
if(hun(id[i][j]))
ans++;
}
printf("%d\n",sum-ans+ans/);
}
return ;
}

 
 

POJ3020 二分图匹配——最小路径覆盖的更多相关文章

  1. POJ 1422 Air Raid(二分图匹配最小路径覆盖)

    POJ 1422 Air Raid 题目链接 题意:给定一个有向图,在这个图上的某些点上放伞兵,能够使伞兵能够走到图上全部的点.且每一个点仅仅被一个伞兵走一次.问至少放多少伞兵 思路:二分图的最小路径 ...

  2. UVA 1201 - Taxi Cab Scheme(二分图匹配+最小路径覆盖)

    UVA 1201 - Taxi Cab Scheme 题目链接 题意:给定一些乘客.每一个乘客须要一个出租车,有一个起始时刻,起点,终点,行走路程为曼哈顿距离,每辆出租车必须在乘客一分钟之前到达.问最 ...

  3. POJ 3020 Antenna Placement【二分匹配——最小路径覆盖】

    链接: http://poj.org/problem?id=3020 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22010#probl ...

  4. POJ:3020-Antenna Placement(二分图的最小路径覆盖)

    原题传送:http://poj.org/problem?id=3020 Antenna Placement Time Limit: 1000MS Memory Limit: 65536K Descri ...

  5. POJ 3020:Antenna Placement(无向二分图的最小路径覆盖)

    Antenna Placement Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6334   Accepted: 3125 ...

  6. hdu3861 强连通分量缩点+二分图最最小路径覆盖

    The King’s Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  7. (匹配 最小路径覆盖)Air Raid --hdu --1151

    链接: http://acm.hdu.edu.cn/showproblem.php?pid=1151 http://acm.hust.edu.cn/vjudge/contest/view.action ...

  8. POJ-1422 Air Raid---二分图匹配&最小路径覆盖

    题目链接: https://vjudge.net/problem/POJ-1422 题目大意: 有n个点和m条有向边,现在要在点上放一些伞兵,然后伞兵沿着图走,直到不能走为止 每条边只能是一个伞兵走过 ...

  9. POJ 1422 二分图(最小路径覆盖)

    Air Raid Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 7278   Accepted: 4318 Descript ...

随机推荐

  1. 测试开发系列之Python开发mock接口(二)

    上一篇咱们已经把开发前的环境准备好了,还需要再做一点准备,你的账户信息是存在哪的呢,当然是存在数据库里的,咱们在去支付,扣钱的时候,肯定是从数据库里面操作的,去更新账户表里面的数据,所以咱们先要把数据 ...

  2. Java运算基础

    计算机对负数的运算 =  先取绝对值的原码----> 然后取反,----->+1   这是负数的补码表示 例如  -5       5的原码= 0000,0101  取反   1111,1 ...

  3. PHP实现INT型,SHORT型,STRING转换成BYTE数组

    实现PHP实现INT型,SHORT型,STRING转换成BYTE数组的转化: class Bytes { public static function integerToBytes($val) { $ ...

  4. 彻底理解javascript 中的事件对象的pageY, clientY, screenY的区别和联系。

    说到底, pageY, clientY, screenY的计算,就是要找到参考点, 它们的值就是: 鼠标点击的点----------- 和参考点指点----------的直角坐标系的距离 stacko ...

  5. 【HDOJ 5399】Too Simple

    pid=5399">[HDOJ 5399]Too Simple 函数映射问题 给出m函数 里面有0~m个函数未知(-1) 问要求最后1~n分别相应仍映射1~n 有几种函数写法(已给定的 ...

  6. 总结下JavaWeb应用里正确显示中文需要的设置

    1.前台页面需要加的设置: <%@ page contentType="text/html; charset=UTF-8"%> html标签后加上<meta ht ...

  7. atitit. hb 原生sql跨数据库解决原理 获得hb 数据库类型执行期获得Dialect

    atitit. hb 原生sql跨数据库解决原理 获得hb 数据库类型执行期获得Dialect   #-----原理 Hibernate 执行期获得Dialect   2010-07-28 12:59 ...

  8. android Graphics类:概述及基本几何图形绘制

    当须要在Android上绘制图形时.就会用到Graphics类.Paint类.Paint就是相当于笔,而Canvas就是 纸.这里叫画布. 所以,凡有跟要要画的东西的设置相关的.比方大小,粗细,画笔颜 ...

  9. QEMU+GDB调试方法

    两年前调试usb/ip开源项目时,就曾用虚拟机远程调试过Windows和Linux系统内核,当时在VMware Workstation上创建两个虚拟机进行调试,也没有记录下如何配置调试,只是大体的还记 ...

  10. 《ASP.NET》数据绑定—DataList

    DataList控件是.NET中的一个控件.DataList控件以表的形式呈现数据(在属性生成器中能够编辑),通过该控件,您能够使用不同的布局来显示数据记录(使用模板编辑).比如,将数据记录排成列或行 ...