Antenna Placement poj 3020 二分图
来源:互联网 发布:知乎招聘 编辑:程序博客网 时间:2024/06/18 04:14
Description
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
Output
Sample Input
27 9ooo**oooo**oo*ooo*o*oo**o**ooooooooo*******ooo*o*oo*oo*******oo10 1***o******
Sample Output
175
Source
#include<cstring>
#include<iostream>
#include<cstdio>
using namespace std;
int str[1001][1010];
int Map[1010][1010];
int match[1010],vis[1010];
int n,m,num;
int dx[]={-1,1,0,0};
int dy[]={0,0,-1,1};
int dfs(int u)
{
for(int i=1;i<=num;i++)
if(!vis[i]&&Map[u][i])
{
vis[i]=1;
if(!match[i]||dfs(match[i]))
{
match[i]=u;
return 1;
}
}
return 0;
}
int main()
{
int t;
cin>>t;
while(t--)
{
num=0;
int sum=0;
memset(str,0,sizeof(str));
memset(Map,0,sizeof(Map));
memset(match,0,sizeof(match));
char ch;
cin>>n>>m;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
cin>>ch;
if(ch=='*')
str[i][j]=++num;
}
}
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
{
if(str[i][j])
{
for(int k=0;k<4;k++)
{
int x=i+dx[k];
int y=j+dy[k];
if(str[x][y])
{
Map[str[i][j]][str[x][y]]=1;
}
}
}
}
for(int i=1;i<=num;i++)
{
memset(vis,0,sizeof(vis));
if(dfs(i))
sum++;
}
printf("%d\n",num-sum/2);
}
}
#include<cstring>
#include<cstdio>
#include<iostream>
using namespace std;
int w[405][405];
int vis[555],s[445];
char Map[45][45];
int v[45][15];
int tt;
int dfs(int a)
{
int i;
for(i=1;i<tt;i++)
{
if(w[a][i]&&!vis[i])
{
vis[i]=1;
if(s[i]==0||dfs(s[i]))
{
s[i]=a;
return 1;
}
}
}
return 0;
}
int main()
{
int t;
int n,m;
int i,j;
cin>>t;
while(t--)
{
memset(w,0,sizeof(w));
cin>>n>>m;
tt=1;
for(i=0;i<n;i++)
{
cin>>Map[i];
for(j=0;j<m;j++)
if(Map[i][j]=='o')
v[i][j]=0;
else
v[i][j]=tt++;
}
for(i=0;i<n;i++)
for(j=0;j<m;j++)
{
if(v[i-1][j]!=0&&i>=1)
w[v[i][j]][v[i-1][j]]=1;
if(v[i+1][j]!=0&&i+1<n)
w[v[i][j]][v[i+1][j]]=1;
if(v[i][j-1]!=0&&j>=1)
w[v[i][j]][v[i][j-1]]=1;
if(v[i][j+1]!=0&&j+1<m)
w[v[i][j]][v[i][j+1]]=1;
}
int ans=0;
memset(s,0,sizeof(s));
for(i=1;i<tt;i++)
{
memset(vis,0,sizeof(vis));
if(dfs(i))
ans++;
}
printf("%d\n",tt-1-ans/2);
}
}
- poj 3020 Antenna Placement 二分图匹配
- poj 3020 Antenna Placement 二分图
- poj 3020 Antenna Placement 二分图匹配
- poj-3020-Antenna Placement-二分图
- Antenna Placement poj 3020 二分图
- 【二分图】poj 3020 Antenna Placement
- 【二分图+最小路径覆盖】北大 poj 3020 Antenna Placement
- poj 3020 Antenna Placement(二分图匹配)
- POJ 3020Antenna Placement(二分图最小顶点覆盖)
- poj 3020 Antenna Placement 二分图最小路径覆盖
- poj 3020 Antenna Placement(二分无向图 匈牙利)
- POJ 3020 Antenna Placement ,二分图的最小路径覆盖
- POJ 3020 Antenna Placement(二分图的最大匹配)
- POJ 3020 Antenna Placement(二分图匹配)
- POJ 题目3020 Antenna Placement(二分图)
- POJ - 3020 Antenna Placement 二分图 最小路径覆盖
- Poj 3020 Antenna Placement (二分图最小路径覆盖)
- POJ 3020 Antenna Placement(二分图最小路径覆盖)
- SpringBoot入门(十三)-热部署
- SpringBoot入门(十四)-注册servlet…
- 加密出错!Illegal key size
- 1001. 害死人不偿命的(3n+1)猜想 (15)
- SpringBoot入门(十五)-定时任务
- Antenna Placement poj 3020 二分图
- 日期转换错误
- spark-环境配置出错
- scala-环境安装出错
- 传入的表格格式数据流(TDS)远程过…
- reactnative 动画实现
- Can not cast from List…
- 程序员如何学习新的技术
- sqlserver数据库数据类型与java数…