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 ...
随机推荐
- 开源免费的.NET图像即时处理的组件ImageProcessor
承接以前的组件系列,这个组件系列旨在介绍.NET相关的组件,让大家可以在项目中有一个更好的选择,社区对于第三方插件的介绍还是比较少的,很多博文的内容主要还是介绍一些简单的操作(很多人都说博客园现在是“ ...
- PHP随机生成随机个数的字母组合示例
在很多系统环境下大家都会用到字母组合各种编码,下面推荐大家非常实用的PHP代码. $num由几个字母组合. $s字母包含大小写,可以自己调配大写还小写. <?php function makec ...
- C#实现无边框窗体点击任务栏图标正常最小化和还原
protected override CreateParams CreateParams{ get { const int WS_MINIMIZEBOX = 0x00020000; // Winuse ...
- windows phone 8.1开发SQlite数据库引用安装
原文出自:http://www.bcmeng.com/windows-phone-sqlite/ windows phone 8.1开发SQlite数据库引用安装 第一步: 安装SQlite forw ...
- C++标准库之stack(各函数及其使用全)
原创作品,转载请注明出处:http://www.cnblogs.com/shrimp-can/p/5283207.html 栈是后入先出的.成员函数有: 1.栈的声明 std::deque<in ...
- Eclipse集成Tomcat教程
(初学者都会问一个问题,就是Eclipse好用还是Myeclipse好用.好吧,这个问题我昨晚才刚刚问完,哈哈,因为我一开始学Java都是直接下了一个MyeClipse来用的,没想过太多.其实也是,两 ...
- javaScript绑定事件委托 demo
事件绑定通常发生在 onload 或 DOMContentReady , 事件绑定占用 处理时间 占用内存, 而且不是每个事件都会被 点击执行. 由此 事件委托 可以优化事件绑定行为.. 事件逐层冒泡 ...
- js的几种简单排序算法及其效率实测
function swap(arr,index1,index2){ var t = arr[index1]; arr[index1] = arr[index2]; arr[index2] = t; } ...
- Jquery EasyUI远程校验,Jquery EasyUI多个自定义校验,EasyUI自定义校验
>>>>>>>>>>>>>>>>>>>>>>>>> ...
- Android自定义View之音频条形图
2016-04-12 17:52 76人阅读 评论(2) 收藏 举报 分类: Android(26) 版权声明:本文为博主原创文章,未经博主允许不得转载. 新建项目,新建MusicRectangl ...