POJ3020 二分图匹配——最小路径覆盖
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
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 二分图匹配——最小路径覆盖的更多相关文章
- POJ 1422 Air Raid(二分图匹配最小路径覆盖)
POJ 1422 Air Raid 题目链接 题意:给定一个有向图,在这个图上的某些点上放伞兵,能够使伞兵能够走到图上全部的点.且每一个点仅仅被一个伞兵走一次.问至少放多少伞兵 思路:二分图的最小路径 ...
- UVA 1201 - Taxi Cab Scheme(二分图匹配+最小路径覆盖)
UVA 1201 - Taxi Cab Scheme 题目链接 题意:给定一些乘客.每一个乘客须要一个出租车,有一个起始时刻,起点,终点,行走路程为曼哈顿距离,每辆出租车必须在乘客一分钟之前到达.问最 ...
- 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(二分图的最小路径覆盖)
原题传送:http://poj.org/problem?id=3020 Antenna Placement Time Limit: 1000MS Memory Limit: 65536K Descri ...
- POJ 3020:Antenna Placement(无向二分图的最小路径覆盖)
Antenna Placement Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6334 Accepted: 3125 ...
- hdu3861 强连通分量缩点+二分图最最小路径覆盖
The King’s Problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- (匹配 最小路径覆盖)Air Raid --hdu --1151
链接: http://acm.hdu.edu.cn/showproblem.php?pid=1151 http://acm.hust.edu.cn/vjudge/contest/view.action ...
- POJ-1422 Air Raid---二分图匹配&最小路径覆盖
题目链接: https://vjudge.net/problem/POJ-1422 题目大意: 有n个点和m条有向边,现在要在点上放一些伞兵,然后伞兵沿着图走,直到不能走为止 每条边只能是一个伞兵走过 ...
- POJ 1422 二分图(最小路径覆盖)
Air Raid Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 7278 Accepted: 4318 Descript ...
随机推荐
- 让Mac OS X专用高速移动硬盘在Linux下也能被读写
MacBook Pro以及iMac等设备都具备雷电接口和USB 3.0接口,配合使用Mac OS X格式化的专用高速移动硬盘读写数据都非常快.那么这种硬盘可以在Linux下被读写吗?其实,Mac OS ...
- 程序防止SqlServer使用SqlServer Profiler跟踪
思路: 1.使用默认函数(fn_trace_getinfo)查询跟踪列表: 2.调用系统存储过程(sp_trace_setstatus)修改跟踪状态. 相关Sql : declare @default ...
- HTTP请求的缓存(Cache)机制
原文地址:http://small.aiweimeng.top/index.php/archives/58.html 先来一张图: ####下面简单的来描述一下HTTP Cache机制: 当资源资源第 ...
- Codeforces 735 E Ostap and Tree
Discription Ostap already settled down in Rio de Janiero suburb and started to grow a tree in his ga ...
- Go视频教程整理转
Go视频教程整理 [Go Web基础]01博客项目设计 |Go视频教程|Go语言基础 http://www.tudou.com/programs/view/gXZb9tGNsGU/ [Go Web基础 ...
- ios Crash Log 分析汇总
方法一: 1.xcode 有自带的symbolicatecrash,可以将.crash文件中的16进制地址转换成可读的函数地址. symbolicatecrash位于: /Applications/X ...
- 系统重装 WIN7如何创建和使用VHD文件
1 在磁盘管理中,点击操作-创建VHD,然后可以创建一个空的VHD文件 2 右击这个磁盘,点击初始化磁盘,然后可以新建简单卷 3 右击这个磁盘,设置为脱机或者联机就可以在计算机中显示和隐藏这个 ...
- html中<li></li>中使用<br>和<li></li>外面使用<br>
</pre><pre> <!DOCTYPE html> <html> <head> <meta http-equiv="Co ...
- 基于bootstrap_网站汇总页面
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- cocos2d-x(vs2012)环境搭建(第一篇)[版本号:cocos2d-x-3.1.1]
1.下载资源 下载cocos2d-x包V3.1.1,下载戳这里: http://www.cocos2d-x.org/download vs2012下载戳这里: http://www.xiazaiba. ...