题目链接 : http://poj.org/problem?id=3020

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+,r),(c,r+),(c-,r), or (c,r-), 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  <= h <=  and  < w <= . 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 ooo**oooo
**oo*ooo*
o*oo**o**
ooooooooo
*******oo
o*o*oo*oo
*******oo *
*
*
o
*
*
*
*
*
*
Sample Output

题意:一个n*m的方阵 一个雷达可覆盖两个*,一个*可与四周的一个*被覆盖,一个*可被多个雷达覆盖问至少需要多少雷达能把所有的*覆盖

方法:把每个*变成数字,查看这些数字可与那些数字相连,然后用二分匹配,把能连得点匹配成对

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<math.h>
#include<queue>
#include<stdlib.h>
#define INF 0x3f3f3f3f
#define met(a,b) memset(a,b,sizeof(a));
#define ll long long
using namespace std;
const int N = ;
int dis[][]={{,},{,},{-,},{,-}};
int cot;
int vis[N],d[N],a[N][N];
int G[N][N];
char str[N][N];
int fin(int s)
{
for(int i=;i<=cot;i++)
{
if(!vis[i] && G[s][i])
{
vis[i]=;
if(!d[i] || fin(d[i]))
{
d[i]=s;
return ;
} }
}
return ;
}
int main()
{
int t,n,m,e,f;
scanf("%d",&t);
while(t--)
{
cot=;met(a,);met(G,);
scanf("%d %d",&n,&m);
for(int i=;i<n;i++)
{
scanf("%s",str[i]);
for(int j=;j<m;j++)
{
if(str[i][j]=='*')
a[i][j]=++cot;
}
}
for(int i=;i<n;i++)
{
for(int j=;j<m;j++)
{
if(str[i][j]=='*')
{
e=a[i][j];
for(int k=;k<;k++)
{
int x=i+dis[k][];
int y=j+dis[k][];
if(x>=&&x<n&&y>=&&y<m&&str[x][y]=='*')
{
f=a[x][y];
G[e][f]=G[f][e]=;
}
}
}
}
}
met(d,);
int ans=;
for(int i=;i<=cot;i++)
{
met(vis,);
if(fin(i))
ans++;
}
printf("%d\n",cot-ans/);
}
return ;
}

还有一种方法

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <stack>
#include <math.h>
#include <queue>
#include <vector>
using namespace std;
#define N 500
#define INF 0x3f3f3f3f
#define ll long long
#define met(a,b) memset(a,b,sizeof(a));
vector<vector<int> >Q;
int dis[][]={{,},{,},{-,},{,-}};
struct node
{
int v,next;
}Map[N<<];
int a[][],vis[N<<],used[N<<];
char str[][];
int s[N<<],l;
void add(int e,int f)
{
Map[l].v=f;
Map[l].next=s[e];
s[e]=l++;
}
int pan(int u)
{
for(int i=s[u];i!=-;i=Map[i].next)
{
int v=Map[i].v;
if(!vis[v])
{
vis[v]=;
if(!used[v] || pan(used[v]))
{
used[v]=u;
return ;
}
}
}
return ;
}
int main()
{
int t,cot,n,m;
scanf("%d",&t);
while(t--)
{
cot=;met(s,-);l=;met(a,);
scanf("%d %d",&n,&m);
for(int i=; i<n; i++)
{
scanf("%s",str[i]);
for(int j=; j<m; j++)
{
if(str[i][j]=='*')
a[i][j]=cot++;
}
}
for(int i=; i<n; i++)
{
for(int j=; j<m; j++)
if(str[i][j]=='*')
{
for(int k=; k<; k++)
{
int x=i+dis[k][];
int y=j+dis[k][];
if(x>= && x<n && y>=&&y<m&&str[x][y]=='*')
add(a[i][j],a[x][y]);
} }
}
met(used,);int sum=;
for(int i=;i<cot;i++)
{
met(vis,);
sum+=pan(i);
}
printf("%d\n",cot--sum/);
}
return ;
}

(poj)3020 Antenna Placement 匹配的更多相关文章

  1. 二分图最大匹配(匈牙利算法) POJ 3020 Antenna Placement

    题目传送门 /* 题意:*的点占据后能顺带占据四个方向的一个*,问最少要占据多少个 匈牙利算法:按坐标奇偶性把*分为两个集合,那么除了匹配的其中一方是顺带占据外,其他都要占据 */ #include ...

  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 【最小边覆盖】

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

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

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

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

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

  6. POJ 3020 Antenna Placement 最大匹配

    Antenna Placement Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6445   Accepted: 3182 ...

  7. poj 3020 Antenna Placement(二分无向图 匈牙利)

    Antenna Placement Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6438   Accepted: 3176 ...

  8. POJ 3020 Antenna Placement

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

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

    链接:poj 3020 题意:一个矩形中,有n个城市'*'.'o'表示空地,如今这n个城市都要覆盖无线,若放置一个基站, 那么它至多能够覆盖本身和相邻的一个城市,求至少放置多少个基站才干使得全部的城市 ...

随机推荐

  1. 二、JSP的3个编译指令,7个动作指令,9个内置对象

    JSP 3个编译指令 1)  page指令(基本不需要用到,使用默认即可) 主要属性: 1.Language:指定脚本所采用的语言类型,现在只支持java 2.Extends:定义当前jsp产生的se ...

  2. JS单词形式的运算符

    1.void 运算表达式并忽略其返回值,比如void (1+2),void (0) <html> <head> <meta http-equiv="conten ...

  3. 流弊博客集锦(updating)

    1.http://ifeve.com/ 2.淘宝的 code project http://code.taobao.org/ http://blog.csdn.net/tenfyguo/article ...

  4. HBase 和 MongoDB在设计上的区别

    转载:http://leongfans.iteye.com/blog/1019383 昨天搜一下mongodb的资料,介绍应用的比较多,原理介绍的不多. 粗略得看了一下,总体来说两者的设计思路差不多, ...

  5. CAS总结之Ticket篇

    国内私募机构九鼎控股打造APP,来就送 20元现金领取地址:http://jdb.jiudingcapital.com/phone.html内部邀请码:C8E245J (不写邀请码,没有现金送)国内私 ...

  6. cocos2d 场景转换的方法执行顺序

    转自:http://shanbei.info/the-cocos2d-scene-conversion-method-execution-order.html 如果你希望在场景转换的过程中使用过渡效果 ...

  7. 有关AES加密的问题

    遇到一个项目,需要用AES加密密码,android的已经写好了,java源码: private static final String AES_OPTIONS = "AES/ECB/PKCS ...

  8. PHP函数ip2long转换IP时数值太大产生负数的解决办法

    有两种办法: 1. bindec( decbin($long))  利用bindec和decbin两个函数转换一次就没有问题了 我一直在用上面的方法,但是在升级到PHP7以后就不起作用了(因为最近只进 ...

  9. 区域医疗移动医疗影像解决方案2--基于FLEX的PACS

    基于Flex的PACS和基于HTML5的PACS,都不是基于DICOM的WADO的方式,即所有的图像操作,移动.缩放.旋转.测量.伪彩.窗宽窗位调整等都是在本地浏览器能够完成,不用和服务器进行频繁的交 ...

  10. 金蝶KIS 13.0专业版破解方法破解安装流程 金蝶KIS 13.0专业版安装流程

    金蝶KIS 13.0安装 1.先安装操作系统Windows server 2008 R2. 2.再安装SQL2008 R2. 3.再安装金蝶KIS 13.0专业版. 在安装时记住须要将系列号设置成为1 ...