题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=654

Robert is a famous engineer. One day he was given a task by his boss. The background of the task was the following:



Given a map consisting of square blocks. There were three kinds of blocks: Wall, Grass, and Empty. His boss wanted to place as many robots as possible in the map. Each robot held a laser weapon which could shoot to four directions (north, east, south, west)
simultaneously. A robot had to stay at the block where it was initially placed all the time and to keep firing all the time. The laser beams certainly could pass the grid of Grass, but could not pass the grid of Wall. A robot could only be placed in an Empty
block. Surely the boss would not want to see one robot hurting another. In other words, two robots must not be placed in one line (horizontally or vertically) unless there is a Wall between them.



Now that you are such a smart programmer and one of Robert's best friends, He is asking you to help him solving this problem. That is, given the description of a map, compute the maximum number of robots that can be placed in the map.



Input




The first line contains an integer T (<= 11) which is the number of test cases. 



For each test case, the first line contains two integers m and n (1<= m, n <=50) which are the row and column sizes of the map. Then m lines follow, each contains n characters of '#', '*', or 'o' which represent Wall, Grass, and Empty, respectively.

Output



For each test case, first output the case number in one line, in the format: "Case :id" where id is the test case number, counting from 1. In the second line just output the maximum number of robots that can be placed in that map.

Sample Input

2

4 4

o***

*###

oo#o

***o

4 4

#ooo

o#oo

oo#o

***#

Sample Output

Case :1

3

Case :2

5


Author: XU, Luchuan

Source: ZOJ Monthly, October 2003

PS:

http://blog.csdn.net/acdreamers/article/details/8654005

这图要用邻接表。 否则会爆内存。

50*50/2! 开1500的二维就OK拉。

代码例如以下:

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
#define MAXN 1547
int LN, RN;//L,R数目
int g[MAXN][MAXN], linker[MAXN];
bool used[MAXN];
char ma[57][57];
int r[MAXN][MAXN], c[MAXN][MAXN];
int head[MAXN];
struct node
{
int x;
int next;
} edge[MAXN<<1];
int cnt = 1;
void addEdge(int x, int y)
{
edge[cnt].x = y;
edge[cnt].next = head[x];
head[x] = cnt++;
}
int dfs(int L)//从左边開始找增广路径
{
int R;
//for(R = 1; R <= RN; R++)
for(int i = head[L]; ~i; i = edge[i].next)
{
R = edge[i].x;
if(!used[R])
{
//找增广路。反向
used[R]=true;
if(linker[R] == -1 || dfs(linker[R]))
{
linker[R] = L;
return 1;
}
}
}
return 0;
}
int hungary()
{
int res = 0 ;
int L;
memset(linker,-1,sizeof(linker));
for( L = 1; L <= LN; L++)
{
memset(used,0,sizeof(used));
if(dfs(L) != 0)
res++;
}
return res;
} int check(int x, int y)
{
if(ma[x][y]=='o' || ma[x][y]=='*')
{
return 1;
}
return 0;
}
void init()
{
cnt = 0;
memset(head,-1,sizeof(head));
memset(g,0,sizeof(g));
memset(c,0,sizeof(c));
memset(r,0,sizeof(r));
}
int main()
{
int t;
int n, m;
int k, L, R; int cas = 0;
scanf("%d",&t);
while(t--)
{
init();
scanf("%d%d",&n,&m);
for(int i = 1; i <= n; i++)
{
scanf("%s",ma[i]+1);
} int cnt1 = 1, cnt2 = 1;
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= m; j++)
{
if(check(i, j))
{
if(r[i][j] == 0)//行
{
for(int k = j; k <= m; k++)
{
if(check(i, k))
{
r[i][k] = cnt1;
}
else
{
break;
}
}
cnt1++;
}
if(c[i][j] == 0)//列
{
for(int k = i; k <= n; k++)
{
if(check(k, j))
{
c[k][j] = cnt2;
}
else
{
break;
}
}
cnt2++;
}
}
}
}
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= m; j++)
{
if(r[i][j] && c[i][j] && ma[i][j]=='o')
{
//g[r[i][j]][c[i][j]] = 1;
//g[c[i][j]][r[i][j]] = 1;
addEdge(r[i][j], c[i][j]);
}
}
}
LN = cnt1;
RN = cnt2;
int ans = hungary();
printf("Case :%d\n",++cas);
printf("%d\n",ans);
}
return 0 ;
}
/*
2
4 4
o***
*###
oo#o
***o
4 4
#ooo
o#oo
oo#o
***#
*/

ZOJ 1654 Place the Robots (二分匹配 )的更多相关文章

  1. zoj 2362 Beloved Sons【二分匹配】

    题目:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2361 来源:http://acm.hust.edu.cn/vjudg ...

  2. ZOJ 1654 Place the Robots建图思维(分块思想)+二分匹配

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=654 AC一百道水题,不如AC一道难题来的舒服. 题意:一个n*m地图 ...

  3. ZOJ 1654 Place the Robots(放置机器人)------最大独立集

    Place the Robots http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1654 Time Limit: 5 Sec ...

  4. ZOJ 1654 Place the Robots

    题目大意: 在空地上放置尽可能多机器人,机器人朝上下左右4个方向发射子弹,子弹能穿过草地,但不能穿过墙, 两个机器人之间的子弹要保证互不干扰,求所能放置的机器人的最大个数 每个机器人所在的位置确定了, ...

  5. ZOJ 1654 Place the Robots(最大匹配)

    Robert is a famous engineer. One day he was given a task by his boss. The background of the task was ...

  6. ZOJ 1654 - Place the Robots (二分图最大匹配)

    题意:在一个m*n的地图上,有空地,草和墙,其中空地和草能穿透攻击光线,而墙不能.每个机器人能够上下左右攻击,问在地图上最多能放多少个不互相攻击的机器人. 这个题和HDU 1045 -  Fire N ...

  7. ZOJ 1654 二分匹配基础题

    题意: 给你一副图, 有草地(*),空地(o)和墙(#),空地上可以放机器人, 机器人向上下左右4个方向开枪(枪不能穿墙),问你在所有机器人都不相互攻击的情况下能放的最多的机器人数. 思路:这是一类经 ...

  8. zoj 1002 Fire Net (二分匹配)

    Fire Net Time Limit: 2 Seconds      Memory Limit: 65536 KB Suppose that we have a square city with s ...

  9. POJ 1274 The Perfect Stall、HDU 2063 过山车(最大流做二分匹配)

    The Perfect Stall Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 24081   Accepted: 106 ...

随机推荐

  1. SpringCloud学习笔记(12)----Spring Cloud Netflix之Hystrix断路器的流程和原理

    工作流程(参考:https://github.com/Netflix/Hystrix/wiki/How-it-Works) 1. 创建一个HystrixCommand或HystrixObservabl ...

  2. SQL 自动记录存储过程,表,函数的创建修改和删除 -相当于SVN一样

         在项目开发过程中,项目管理者通常都很希望对项目的开发进展有一个日志的记录.代码的记录和管理可以通过TFS或者VSS等工具去管理.但是数据库却没有记录开发日志这一功能.这在实际开发中很不方便, ...

  3. Python链表

    class Node: ''' 节点类 链表节点结构 data next data: 节点保存的数据 _next: 保存下一个节点对象 ''' def __init__(self, data, pne ...

  4. luogu P3674 小清新人渣的本愿(莫队+bitset)

    这题是莫队维护bitset. 然而我并不会bitset以前讲过认为不考就没学 我真的太菜了. 首先维护一个权值的bitset--s. 操作3比较简单,我们可以\(\sqrt{x}\)枚举约数然后判断就 ...

  5. [codevs3955]最长严格上升子序列(加强版)

    题目大意:给你一个序列,要你求该序列中最长严格上升子序列的长度. 解题思路:此题算是一道LIS模板题.普通的$O(n^2)$的LIS是会TLE的,因为$n\le 1000000$,所以此题要用单调队列 ...

  6. Ubuntu16.04 lnmp 环境搭建

    Ubuntu16.04 lnmp 环境搭建 nginx 安装 sudo apt-add-repository ppa:nginx/stablesudo apt-add-repository ppa:o ...

  7. vue路由知识整理

    vue路由知识整理 对于单页应用,官方提供了vue-router进行路由跳转的处理.我们已经可以通过组合组件来组成应用程序,当你要把 vue-router 添加进来,我们需要做的是,将组件(compo ...

  8. 在oracle中采用connect by prior来实现递归查询

    注明:该文章为引用别人的文章,链接为:http://blog.csdn.net/apicescn/article/details/1510922 , 记录下来只是为了方便查看 原文: connect ...

  9. 洛谷 P1193 洛谷团队训练VS传统团队训练

    P1193 洛谷团队训练VS传统团队训练 题目背景 “在中学的信息学教育领域,洛谷无疑是一个相当受欢迎的辅助网站.同时有百余所学校正在通过洛谷进行信息学竞赛(以后简称OI)的教育.洛谷之所以如此受欢迎 ...

  10. 阿里云CentOS系统配置iptables防火墙

    虽说阿里云推出了云盾服务,但是自己再加一层防火墙总归是更安全些,下面是我在阿里云vps上配置防火墙的过程,目前只配置INPUT.OUTPUT和FORWORD都是ACCEPT的规则 一.检查iptabl ...