题目链接 : 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. MFC版美女找茬

    今天心情:捡了个闲暇. 前几天工作出了个漏洞,电话会议时候怎么都是忽大忽小的声音,实在没听清电话会议的内容,完了依据想象交了一个设计方案,之后便是赋闲. 进入正题,美女找茬实现不难,没有设计上的难度, ...

  2. Windows Azure Website类别、限制条件

    在Azure中Website是一个典型的SAAS,用户可以很容易地搭建自己想要的网站,可以基于多种编程语言(ASP.NET/ASP/PHP/Node.JS等)和网站框架. Website有三种分类分别 ...

  3. Attribute特性验证模型model

    数据验证我们往往分为前台验证和后台验证,而我们的后台验证每到一个方法中就要去验证一次,这样的代码想想都难以维护,这篇我们这篇文章就是为了解决这样的问题.用attribute 这个特性来解决这样的问题 ...

  4. js获取上传文件内容(未完待续)

    js 获取上传文件的字节数及内容 <div> 上传文件 : <input type="file" name = "file" id = &qu ...

  5. java线程知识点

    1. 进程与线程 一个进程拥有多个线程,多个线程共享进程的内存块.操作系统不分配新的内存,因此线程之间通信很容易.不同的进程因处于不同的内存块,因此进程之间通信较为困难. 进程:每个进程都有独立的代码 ...

  6. 好记心不如烂笔头,ssh登录 The authenticity of host 192.168.0.xxx can't be established. 的问题

    用ssh登录一个机器(换过ip地址),提示输入yes后,屏幕不断出现y,只有按ctrl + c结束 错误是:The authenticity of host 192.168.0.xxx can't b ...

  7. 【转】placement new

    原文:http://www.cnblogs.com/wanghetao/archive/2011/11/21/2257403.html 1. placement new的含义placement new ...

  8. .NET连接MySQL数据库的方法实现

    突然对.NET连接MySQL数据库有点兴趣,于是乎网上到处找资料,学习MySQL的安装,MySQL的使用等等等等,终于搞定了! 最终效果就是显示数据库中数据表的数据: 首先,当然要有MySQL数据库啦 ...

  9. ZOJ 3822 Domination 期望dp

    Domination Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.zju.edu.cn/onlinejudge/showProblem ...

  10. CPU相关信息

    unit untCpuInfo;interface{ 获取 CPU 制造商 }function GetCpuFactory: String;{ 获取 CPU 家族系统 }function GetCpu ...