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 ...
随机推荐
- PHP语言开发微信公众平台(订阅号)之curl命令
在开发过程中,经常会遇到要求用curl命令调用接口的情况 那么,什么是curl,简单来说curl是一个利用url语法规定来传输文件和哦数据的工具,支持很多协议,如 http.ftp.telent 等, ...
- JAVA基础知识(2)--队列的操作
队列是一种线性表,它只允许在该表中的一端插入,在另一端删除. 允许插入的一端叫做队尾(rear),允许删除的一端叫做队头(front): 下面用Java的数组进行模拟队列的操作: /**2015-07 ...
- 日新进用户200W+,解密《龙之谷》手游背后的压测故事
2017年3月,腾讯正式于全平台上线了<龙之谷>手游,次日冲到了App Store畅销排行第二的位置,并维持到了现在.上线当日百度指数超过40万,微信游戏平台数据显示预约数780多万,而据 ...
- React Native 之 数据持久化
前言 因为 实战项目系列 涉及到数据持久化,这边就来补充一下. 如本文有错或理解偏差欢迎联系我,会尽快改正更新! 如有什么问题,也可直接通过邮箱 277511806@qq.com 联系我. demo链 ...
- JvisualVM、JMC监控远程服务器
修改服务器上jmxremote.access与jmxremote.password,输入命令: find -name jmxremote.access进入该jmxremote.access文件所在目录 ...
- iOS最好用的引导页
最近项目结束的时候又要改引导页,之前写的启动页改起来太麻烦了,所以就直接封装一个,功能可能还不是很完善,但是感觉用起来也比较方便,在这里和大家分享一下. 这是github的下载地址:https://g ...
- Vijos1523贪吃的九头龙【树形DP】
贪吃的九头龙 传说中的九头龙是一种特别贪吃的动物.虽然名字叫"九头龙",但这只是说它出生的时候有九个头,而在成长的过程中,它有时会长出很多的新头,头的总数会远大于九,当然也会有旧头 ...
- Excel图表-创意雷达图-原创图表
p{ font-size: 15px; } .alexrootdiv>div{ background: #eeeeee; border: 1px solid #aaa; width: 99%; ...
- Myeclipse8.5开发-程序发布
1.新建focus.xml文件. 2.添加如下内容 <Context path="/focus" docBase="F:\Workspaces\MyEcli ...
- java中GUI的awt和Swing的知识点
刚刚学习了java的GUI,写了几个程序,基本熟悉了awt和Swing,下面和大家分享一下知识点 1.JFrame的层次结构 参考:http://tieba.baidu.com/p/200421612 ...