(poj)3020 Antenna Placement 匹配
题目链接 : 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 匹配的更多相关文章
- 二分图最大匹配(匈牙利算法) POJ 3020 Antenna Placement
题目传送门 /* 题意:*的点占据后能顺带占据四个方向的一个*,问最少要占据多少个 匈牙利算法:按坐标奇偶性把*分为两个集合,那么除了匹配的其中一方是顺带占据外,其他都要占据 */ #include ...
- poj 3020 Antenna Placement(最小路径覆盖 + 构图)
http://poj.org/problem?id=3020 Antenna Placement Time Limit: 1000MS Memory Limit: 65536K Total Sub ...
- POJ 3020 Antenna Placement 【最小边覆盖】
传送门:http://poj.org/problem?id=3020 Antenna Placement Time Limit: 1000MS Memory Limit: 65536K Total ...
- POJ 3020 Antenna Placement【二分匹配——最小路径覆盖】
链接: http://poj.org/problem?id=3020 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22010#probl ...
- POJ 3020——Antenna Placement——————【 最小路径覆盖、奇偶性建图】
Antenna Placement Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u S ...
- POJ 3020 Antenna Placement 最大匹配
Antenna Placement Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6445 Accepted: 3182 ...
- poj 3020 Antenna Placement(二分无向图 匈牙利)
Antenna Placement Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6438 Accepted: 3176 ...
- POJ 3020 Antenna Placement
Antenna Placement Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5645 Accepted: 2825 Des ...
- poj 3020 Antenna Placement (最小路径覆盖)
链接:poj 3020 题意:一个矩形中,有n个城市'*'.'o'表示空地,如今这n个城市都要覆盖无线,若放置一个基站, 那么它至多能够覆盖本身和相邻的一个城市,求至少放置多少个基站才干使得全部的城市 ...
随机推荐
- java基础理论知识的一些总结
在学习Java初期,由于我们是刚开始接触Java,我们不仅需要牢牢掌握Java的基础理论知识,来为我们后面对Java更深层次的学习打好基础,而且我们需要养成编程人的思想习惯.来我们一起来探索Java基 ...
- SQLite使用教程3 数据类型
http://www.runoob.com/sqlite/sqlite-data-types.html SQLite 数据类型 SQLite 数据类型是一个用来指定任何对象的数据类型的属性.SQLit ...
- Xcode repository host is unreachable
遇到这个错误,首先不要急.按照如下方法即可(如果你的svn地址没有问题的话): url要使用域名,所以映射下 1. 修改host:在应用程序里面打开终端(terminal),输入 sudo vi /e ...
- Oracle 11g系统自己主动收集统计信息的一些知识
在11g之前,当表的数据量改动超过总数据量的10%,就会晚上自己主动收集统计信息.怎样推断10%.之前的帖子有研究过:oracle自己主动统计信息的收集原理及实验.这个STALE_PERCENT=10 ...
- ShowcaseView-master
ShowcaseView.rar
- send,recv,sendto,recvfrom
send函数 int send( SOCKET s, const char FAR *buf, int len, int flags ); 不论是客户还是server应用程序都用se ...
- WebStorm 6.0下运行pomelo项目
最近想使用WebStorm来写pomelo,初次使用WebStorm,网上找了老半天根本没有介绍WebStorm如何创建或者打开运行pomelo的教程,网易pomelo官网介绍的使用 WebStorm ...
- 笨办法学C 练习
http://c.learncodethehardway.org/book/index.html
- BugZilla的安装过程简明教程
Bugzilla+Mysql+iis+perl模块+ ActivePerl 安装过程 (原:http://www.cnblogs.com/Warmsunshine/archive/2012/03/25 ...
- Setting up a database adapter
Setting up a database adapter zend-db provides a general purpose database abstraction layer. At its ...