The Castle
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 8317 Accepted: 4693

Description

1 2 3 4 5 6 7

#############################

1 # | # | # | | #

#####—#####—#---#####—#

2 # # | # # # # #

#—#####—#####—#####—#

3 # | | # # # # #

#—#########—#####—#---#

4 # # | | | | # #

#############################

(Figure 1)

# = Wall

| = No wall

- = No wall

Figure 1 shows the map of a castle.Write a program that calculates

  1. how many rooms the castle has
  2. how big the largest room is
    The castle is divided into m * n (m<=50, n<=50) square modules. Each such module can have between zero and four walls.

Input

Your program is to read from standard input. The first line contains the number of modules in the north-south direction and the number of modules in the east-west direction. In the following lines each module is described by a number (0 <= p <= 15). This number is the sum of: 1 (= wall to the west), 2 (= wall to the north), 4 (= wall to the east), 8 (= wall to the south). Inner walls are defined twice; a wall to the south in module 1,1 is also indicated as a wall to the north in module 2,1. The castle always has at least two rooms.

Output

Your program is to write to standard output: First the number of rooms, then the area of the largest room (counted in modules).

Sample Input

4
7
11 6 11 6 3 10 6
7 9 6 13 5 15 5
1 10 12 7 13 7 5
13 11 10 8 10 12 13

Sample Output

5
9

Source

IOI 1994

问题链接:POJ1164 The Castle
问题简述:(略)
问题分析
    这是一个搜索问题,用DFS实现。
程序说明:(略)
参考链接:(略)
题记:(略)

AC的C语言程序如下:

/* POJ1164 The Castle */#include <stdio.h>int drow[] = {0, -1, 0, 1};
int dcol[] = {-1, 0, 1, 0};#define N 50
int maze[N][N], n, m, sum, cnt;void dfs(int row, int col)
{int s = maze[row][col], i;sum++;maze[row][col] = -1;for(i = 0; i < 4; i++) {if(s % 2 == 0) {int nrow = row + drow[i];int ncol = col + dcol[i];if(nrow >= 0 && nrow < n && ncol >= 0 && ncol < m && maze[nrow][ncol] != -1)dfs(nrow, ncol);}s /= 2;}
}int main(void)
{int maxsum, i, j;while(scanf("%d%d", &n, &m) != EOF) {for(i = 0; i < n; i++)for(j = 0; j < m; j++)scanf("%d", &maze[i][j]);cnt = maxsum = 0;for(i = 0; i < n; i++)for(j = 0; j < m; j++)if(maze[i][j] != -1) {sum = 0;dfs(i, j);cnt++;if(sum > maxsum)maxsum = sum;}printf("%d\n%d\n", cnt, maxsum);}return 0;
}

POJ1164 The Castle【DFS】相关推荐

  1. Bailian2815 城堡问题【DFS】

    2815:城堡问题 总时间限制: 1000ms 内存限制: 65536kB 描述 1 2 3 4 5 6 7 ############################# 1 # | # | # | | ...

  2. Bailian2816 红与黑【DFS】

    2816:红与黑 总时间限制: 1000ms 内存限制: 65536kB 描述 有一间长方形的房子,地上铺了红色.黑色两种颜色的正方形瓷砖.你站在其中一块黑色的瓷砖上,只能向相邻的黑色瓷砖移动.请写一 ...

  3. NUC1158 Lake Counting【DFS】

    Lake Counting 时间限制: 1000ms 内存限制: 65536KB 通过次数: 1总提交次数: 1 问题描述 Due to recent rains, water has pooled ...

  4. NUC1399 Sum It Up【DFS】

    Sum It Up 时间限制: 1000ms 内存限制: 65535KB 通过次数: 1总提交次数: 1 问题描述 Given a specified total t and a list of n ...

  5. HDU1181 变形课【DFS】(废除)

    新题解参见:HDU1181 变形课[DFS+关系闭包+bitset] 变形课 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 13107 ...

  6. 【DFS】巧妙取量的倒油问题

    题目描述 [题目描述]  有三个容器,容量分别为 a,b,c(a> b > c ),一开始a装满油,现在问是否只靠abc三个容器量出k升油.如果能就输出"yes",并且 ...

  7. [kuangbin]专题三 Dancing Links Squiggly Sudoku HDU - 4069【DFS】【精确覆盖】

    [题目描述] Today we play a squiggly sudoku, The objective is to fill a 9*9 grid with digits so that each ...

  8. 【DFS】不撞南墙不回头—深度优先搜索算法[Deep First Search]

    今天上午听到,那个非常6+1的李咏先生因癌症去世 DFS算法的基本模型 深度下,不撞南墙不回头,就是一直往后找,知道没有路了,向后返回. 想起一首民谣,<可能否>--木小雅 https:/ ...

  9. NUC1333 Knight Moves【DFS】

    Knight Moves 时间限制: 1000ms 内存限制: 65535KB 问题描述 A friend of you is doing research on the Traveling Knig ...

最新文章

  1. wsl for pycharm vscode
  2. java for 执行顺序_java – @BeforeMethod和继承 – 执行顺序(TestNG)
  3. 嬴彻CEO:自动驾驶技术只有依托量产,才有持久优势
  4. 老公和老婆的15个关于......
  5. PCB板设计的12个细节,你做对了吗?
  6. HDU:4185-Oil Skimming
  7. 微信小程序js数组初始化_微信小程序 数组(增,删,改,查)等操作实例详解...
  8. 阿里技术专家 分享 DDD(Domain-Driven Design 领域驱动设计)
  9. 【斗鱼直播源】浏览器抓取真实直播源地址(纯前端JS PHP解析源码)
  10. Vue-amap 实现获取定位功能
  11. 《蛋仔派对》通关小技巧
  12. docker-compose开机自启动设置
  13. 外网浏览器访问 docker 容器内服务
  14. 魅族pro 6完美开启usb调试模式的经验
  15. App启动优化-一顿操作猛如虎
  16. 带例子的测试用例模板
  17. FAQ(88): The HTTP response from the server [404] did not permit the HTTP upgrade to WebSocket?
  18. 读书有益——》《让我留在你身边》
  19. FPGA解析串口协议帧3.0版本,增加了错误重发功能,提供仿真文件以及源码
  20. 物联网大学生创新创业项目

热门文章

  1. 树莓派boot分区cmdline.txt
  2. oracle——服务器同时安装服务端和客户端冲突
  3. goland设置代码颜色主题(同Sublime Text 3的代码颜色一样)
  4. 湖南省计算机二级tc,湖南计算机二级考试大纲,重点内容谢谢!
  5. 的ppt_PPT模板中国风PPT模板
  6. 计算机视觉三大会议——ICCV、ECCV和CVPR
  7. java 同步和异步_知道什么叫同步和异步吗?
  8. 应急响应之ARP欺骗
  9. Oracle数据库案例整理-Oracle系统执行时故障-内存过少导致分配共享内存失败
  10. 认识Python基础环境搭建