Place the Robots


Time Limit: 5 Seconds     
Memory Limit: 32768 KB


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

题意:有个 n * m地图,地图由方格组成,#代表墙壁, *代表草地,o代表空地。

如今要在地图上放置机器人,每一个机器人都配备了激光枪,能够向上下左右四个方向开枪。发射的激光能够穿透草地。但不能穿透墙壁,机器人仅仅能放置在空地上。两个机器人不能放置在同一行同一列。除非他们之间有一堵墙隔开,问地图上能够放置的机器人的最大数目。

解题:这题和HDU5093基本一模一样。题中有草地,我们根本不用管,具体思路请看 : HDU5093

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; int map[51 * 50][51 * 50];
char str[51][51];
int x[51][51], x1;
int y[51][51], y1;
int used[51 * 51];
int link[51 * 51];
int n, m; void init(){
memset(map, 0, sizeof(map));
memset(x, 0, sizeof(x));
memset(y, 0, sizeof(y));
} void creat_x(){
x1 = 1;
for(int i = 0; i < n; ++i){
for(int j = 0; j < m; ++j){
if(str[i][j] == 'o')
x[i][j] = x1;
if(str[i][j] == '#')
x1++;
}
x1++;
}
} void creat_y(){
y1 = 1;
for(int j = 0; j < m; ++j){
for(int i = 0; i < n; ++i){
if(str[i][j] == 'o')
y[i][j] = y1;
if(str[i][j] == '#')
y1++;
}
y1++;
}
} void getmap(){
creat_x();
creat_y();
for(int i = 0; i < n; ++i){
for(int j = 0; j < m; ++j)
if(str[i][j] == 'o')
map[x[i][j]][y[i][j]] = 1;
}
} bool dfs(int x){
for(int i = 1; i < y1; ++i){
if(map[x][i] && !used[i]){
used[i] = 1;
if(link[i] == -1 || dfs(link[i])){
link[i] = x;
return true;
}
}
}
return false;
} int hungary(){
int ans = 0;
memset(link, -1, sizeof(link));
for(int j = 1; j < x1; ++j){
memset(used, 0, sizeof(used));
if(dfs(j))
ans++;
}
return ans;
}
int main (){
int T;
int k = 1;
scanf("%d", &T);
while(T--){
init();
scanf("%d%d", &n, &m);
for(int i = 0; i < n; ++i)
scanf("%s", str[i]);
getmap();
printf("Case :%d\n", k++);
int sum = hungary();
printf("%d\n", sum);
}
return 0;
}

最新文章

  1. linux中~和/的区别
  2. 82 fsck-检查与修复 Linux 档案系统
  3. GIT版本库回滚【图文版】
  4. windows 7系统下出现某盘回收站损坏解决办法
  5. 关于使用flexible.js自适应页面,发现文字很多时,字体会变大的问题的原因和解决方案
  6. Python基础5- 运算符
  7. 【转载】linux tail命令的使用方法详解
  8. 解压缩框架--SSZipArchive
  9. Spring MVC 之文件上传(七)
  10. 2014年互联网IT待遇【转载】
  11. 【转】有向图强连通分量的Tarjan算法
  12. WiPlug_百度百科
  13. flex布局之兼容
  14. vue在jsx中使用for循环
  15. Oracle JDK 1.8 openJDK11 定制化JDK
  16. 用 LSTM 做时间序列预测的一个小例子(转自简书)
  17. java Timer 定时每天凌晨0点执行任务
  18. [c/c++] programming之路(24)、字符串(五)——字符串插入,字符串转整数,删除字符,密码验证,注意事项
  19. vs2017 遇到异常。这可能是由某个扩展导致的。奇妙的解决方式
  20. scrapy shell的作用

热门文章

  1. DIV+CSS设计时浏览器兼容性
  2. MSSQL:查看作业情况
  3. sleep()和wait()的区别
  4. 前端-Vue结构思维导图笔记
  5. JavaScript中比较运算符的使用
  6. JavaScript中Null和Undefined的区别
  7. Java 将要上传的文件上传至指定路径代码实现
  8. eas之编辑界面中分录默认携带的标题栏
  9. 爬取某网站景区列表并保存为csv文件
  10. 实体服务器安装centos7过程记录