poj3020二分图匹配
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
题真是巨长,实在看不下去,还有好多生词!直接看样例做的。
题意:给一个图,用两个格子覆盖全部*,可以重复(和上一题这么像?)
题解:和上一题几乎一模一样,只是需要把多余的*加上就行了,这里我把上一题题解放一下http://www.cnblogs.com/acjiumeng/p/6741545.html
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define pi acos(-1)
#define ll long long
#define mod 1000000007 using namespace std; const int N=+,maxn=+,inf=0x3f3f3f3f; int n,m,col,row;
char ma[N][N];
int color[N],u[N][N];
bool used[N],ok[N][N]; bool match(int x)
{
for(int i=;i<=row;i++)
{
if(ok[x][i]&&!used[i])
{
used[i]=;
if(color[i]==||match(color[i]))
{
color[i]=x;
return ;
}
}
}
return ;
}
int solve()
{
int ans=;
memset(color,,sizeof color);
for(int i=;i<=col;i++)
{
memset(used,,sizeof used);
ans+=match(i);
}
return ans;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie();
int t;
cin>>t;
while(t--){
cin>>n>>m;
int res=;
for(int i=;i<=n;i++)
for(int j=;j<=m;j++)
{
cin>>ma[i][j];
if(ma[i][j]=='*')res++;
}
memset(u,,sizeof u);
col=row=;
for(int i=;i<=n;i++)
{
for(int j=;j<=m;j++)
{
if((i+j)%==&&ma[i][j]=='*')u[i][j]=++col;
if((i+j)%==&&ma[i][j]=='*')u[i][j]=++row;
}
}
/* for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
cout<<u[i][j];
cout<<endl;
}*/
memset(ok,,sizeof ok);
for(int i=;i<=n;i++)
{
for(int j=;j<=m;j++)
{
if(ma[i][j]=='*')
{
if((i+j)%==)
{
if(i+<=n&&ma[i+][j]=='*')ok[u[i][j]][u[i+][j]]=;
if(j+<=n&&ma[i][j+]=='*')ok[u[i][j]][u[i][j+]]=;
if(i->=&&ma[i-][j]=='*')ok[u[i][j]][u[i-][j]]=;
if(j->=&&ma[i][j-]=='*')ok[u[i][j]][u[i][j-]]=;
}
else
{
if(i+<=n&&ma[i+][j]=='*')ok[u[i+][j]][u[i][j]]=;
if(i+<=n&&ma[i+][j]=='*')ok[u[i][j+]][u[i][j]]=;
if(i->=&&ma[i-][j]=='*')ok[u[i-][j]][u[i][j]]=;
if(j->=&&ma[i][j-]=='*')ok[u[i][j-]][u[i][j]]=;
}
}
}
}
cout<<res-solve()<<endl;
}
return ;
}
poj3020二分图匹配的更多相关文章
- POJ3020 二分图匹配——最小路径覆盖
		
Description The Global Aerial Research Centre has been allotted the task of building the fifth gener ...
 - poj3020 二分图匹配 最大独立集
		
这是一道水题, 这里是最大流解法,之后再补 坑在又忘了反向建边了 题意:给你二维bool数组,让你求出能用多米诺骨牌覆盖所有 1 且骨牌最少的放法(因为多米诺骨牌1*2的结构方便描述,原题没有),原本 ...
 - POJ3020:Antenna Placement(二分图匹配)
		
Antnna Placement Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11093 Accepted: 5459 ...
 - UVA 12549 - 二分图匹配
		
题意:给定一个Y行X列的网格,网格种有重要位置和障碍物.要求用最少的机器人看守所有重要的位置,每个机器人放在一个格子里,面朝上下左右四个方向之一发出激光直到射到障碍物为止,沿途都是看守范围.机器人不会 ...
 - POJ 1274 裸二分图匹配
		
题意:每头奶牛都只愿意在她们喜欢的那些牛栏中产奶,告诉每头奶牛愿意产奶的牛棚编号,求出最多能分配到的牛栏的数量. 分析:直接二分图匹配: #include<stdio.h> #includ ...
 - BZOJ1433 ZJOI2009 假期的宿舍 二分图匹配
		
1433: [ZJOI2009]假期的宿舍 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 2375 Solved: 1005[Submit][Sta ...
 - HDU1281-棋盘游戏-二分图匹配
		
先跑一个二分图匹配,然后一一删去匹配上的边,看能不能达到最大匹配数,不能这条边就是重要边 /*----------------------------------------------------- ...
 - HDU 1083 网络流之二分图匹配
		
http://acm.hdu.edu.cn/showproblem.php?pid=1083 二分图匹配用得很多 这道题只需要简化的二分匹配 #include<iostream> #inc ...
 - hdu 5727 Necklace dfs+二分图匹配
		
Necklace/center> 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5727 Description SJX has 2*N mag ...
 
随机推荐
- self-question
			
需要即刻提升的几大能力: 1.重装系统和安装各种软件 2.自学能力,多从实际案例中总结,多归纳反思 3.拓展人际关系,和别人沟通交流 4.遇到困难迎刃而上,而不是回避退缩
 - 谷歌开源图片压缩算法Guetzli实测体验报告
			
谷歌大神又出开源新技术啦,这次是对JPEG格式的图片采用全新算法重新编码,输出的图片还是JPEG但是图片大小明显缩小,而质量不但没有损失,甚至还更加优化,速速来体验一把. 一.环境安装 下载谷歌开源软 ...
 - win10+vs2010+cuda7.5安装及配置
			
http://blog.csdn.net/u011821462/article/details/50145221 这篇博客已经写得很详细了.
 - 常见排序算法-Python实现
			
常见排序算法-Python实现 python 排序 算法 1.二分法 python 32行 right = length- : ] ): test_list = [,,,,,, ...
 - CentOS下安装node
			
下载 wget https://nodejs.org/dist/v7.7.4/node-v7.7.4-linux-x64.tar.gz 解压 tar -zxvf node-v7.7.4-linux-x ...
 - Java环境----JDK开发环境搭建及环境变量配置
			
1.啥是jdk? jdk的是java development kit的缩写,意思是java程序开发的工具包. jdk的版本,一共有三种,标准版(j2se),企业版(j2ee),移动设备版(j2me). ...
 - JAVA加密算法系列-AES
			
package ***; import java.io.UnsupportedEncodingException; import java.security.InvalidKeyException; ...
 - Memcached与MySQL数据同步
			
1.介绍 在生产环境中,我们经常使用MySQL作为应用的数据库.但是随着用户的增多数据量的增大,我们将会自然而然的选择Memcached作为缓存数据库,从而减小MySQL的压力.但是memcached ...
 - day001-html知识点总结(二)不常见但很重要的元素汇总
			
一..vertical-align:设置垂直对齐方式,主要用于: 1.单元格内容的垂直对齐 2.对于行内块级元素,如<img>,设置行内元素的基线相对于该行内块级元素的所在行的基线对齐,例 ...
 - cloud-init 典型应用 - 每天5分钟玩转 OpenStack(174)
			
本节介绍几个 cloud-init 的典型应用:设置 hostanme,设置用户初始密码,安装软件. 设置 hostname cloud-init 默认会将 instance 的名字设置为 hostn ...