K - Children of the Candy Corn

Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u

Description

The cornfield maze is a popular Halloween treat. Visitors are shown the entrance and must wander through the maze facing zombies, chainsaw-wielding psychopaths, hippies, and other terrors on their quest to find the exit.

One popular maze-walking strategy guarantees that the visitor will eventually find the exit. Simply choose either the right or left wall, and follow it. Of course, there's no guarantee which strategy (left or right) will be better, and the path taken is seldom the most efficient. (It also doesn't work on mazes with exits that are not on the edge; those types of mazes are not represented in this problem.)

As the proprieter of a cornfield that is about to be converted into a maze, you'd like to have a computer program that can determine the left and right-hand paths along with the shortest path so that you can figure out which layout has the best chance of confounding visitors.

Input

Input to this problem will begin with a line containing a single integer n indicating the number of mazes. Each maze will consist of one line with a width, w, and height, h (3 <= w, h <= 40), followed by h lines of w characters each that represent the maze layout. Walls are represented by hash marks ('#'), empty space by periods ('.'), the start by an 'S' and the exit by an 'E'.

Exactly one 'S' and one 'E' will be present in the maze, and they will always be located along one of the maze edges and never in a corner. The maze will be fully enclosed by walls ('#'), with the only openings being the 'S' and 'E'. The 'S' and 'E' will also be separated by at least one wall ('#').

You may assume that the maze exit is always reachable from the start point.

Output

For each maze in the input, output on a single line the number of (not necessarily unique) squares that a person would visit (including the 'S' and 'E') for (in order) the left, right, and shortest paths, separated by a single space each. Movement from one square to another is only allowed in the horizontal or vertical direction; movement along the diagonals is not allowed.

Sample Input

2
8 8
########
#......#
#.####.#
#.####.#
#.####.#
#.####.#
#...#..#
#S#E####
9 5
#########
#.#.#.#.#
S.......E
#.#.#.#.#
#########

Sample Output

37 5 5 17 17 9

//还没看懂题

最新文章

  1. u-boot ctr0.S详解 包含_main函数
  2. jquery日历datepicker的使用方法
  3. ShineTime 是一个效果非常精致的缩略图相册
  4. 如何处理Cookie存储和读取中文乱码问题
  5. FusionCharts报错
  6. windows下 python3.5+tensorflow 安装
  7. 聊聊Unity的Gamma校正以及线性工作流
  8. 银盒子智慧餐厅硬件尺寸规格&amp;推荐机型
  9. Java 骚操作--生成二维码
  10. underscore.js源码解析【集合】
  11. blfs(systemv版本)学习笔记-配置远程连接显示中文
  12. Shiro学习笔记四(Shiro集成WEB)
  13. NodeJS入门篇
  14. 通过Application存取公共数据比如登录信息等..
  15. Java Servlet调用数据库复习
  16. 如何掌握jQuery插件开发(高能)
  17. 20145240《Java程序设计》第三周学习总结
  18. Android 主线程和子线程通信问题
  19. 标准C程序设计七---66
  20. 暴力(python)

热门文章

  1. ubuntu各版本代号(更新至15.04)及各版本下载地址等
  2. 配置 mybatis的 log4j.properties
  3. Centos6.2上做nginx和tomcat的集成及负载均衡(已实践)
  4. python基础 实战作业 ---Excel基本读写与数据处理
  5. jumpserverv0.5.0 基于 CentOS7安装部署
  6. 云解析DNS使用教程
  7. Gherkin关键字
  8. php中的可变变量、可变函数、匿名函数
  9. spring事务管理源码解析--加了@Transactional注解后Spring究竟为我们做了哪些事情?
  10. 牛散NO.1:MACD计啜诱多,勾魂枪连环夺命时