2 shunfurh shunfurh 于 2017.09.02 21:17 提问

Galou is back!

Problem Description
The famous witch is back. After killing an incredible amount of monsters in order to find a hidden treasure, Zak Galou decided to buy vineyards in Burgundy and retired. Everything was calm in his new life, until the day that his farm tractor stopped working. His tractor’s engine works based on a mechanism of gears. The engine can be represented by a bidimensional grid. At most one gear can be attached to each position of the grid.

All the gears are identical and can mesh with adjacent gears. In this grid, a gear can have up to six other adjacent gears, see figure below:

Under normal utilization, when the tractor is started, some of the gears are initially activated and try to turn clockwise. When a gear tries to turn in one direction, all the adjacent gears try to turn in the opposite direction.

When Zak Galou opened his engine he noticed that it had been sabotaged (probably by a jealous treasure hunter who was not able to find the treasure). Some of the gears were removed from the engine and others have been added to it. As a consequence, some of the gears were immobile. A gear can be immobile either if it is free or if it is blocked. A gear is free when it is not an initially activated gear and no adjacent gear is trying to turn. A gear is blocked when it is trying to turn in both directions at the same time. For example, consider that there are three gears in the engine as shown in the figure below. If any of the gears is initially activated when the tractor is started, all of them will be blocked. If none of the gears are initially activated, all of them will be free.

As a part of the work of fixing his tractor, Zak Galou asks for your help to solve the following problem. Given the description of the engine and the gears that are initially activated in the clockwise direction, he wants to know for each gear, what is its state when the tractor is started:
turn clockwise, turn counter-clockwise, free or blocked.

Input
The input contains several test cases. The first line of a test case contains two integers R and C, separated by a single space, representing respectively the number of rows and columns of the engine grid (1 <= R,C <= 100). The next R lines describe the engine. The i-th line represents the i-th row of the engine and contains C characters. The character “.” indicates that there is no gear in the corresponding position, the character “*” indicates that there is a gear that is not initially activated when the engine is started and an “I” indicates that there is a gear that is initially activated when the engine is started. Notice that, for simplicity reasons, the parallelogram representing the engine grid is described in the input as if it was a rectangle with each row left aligned. The end of input is indicated by R = C = 0.

Output
For each test case, your program must output R + 1 lines. The first line must be empty; each of the following R lines must have C characters. The characters printed must represent the state of each position of the grid when the engine is started. Print a “.” if there is no gear in the position; a “(” if there is a gear turning in the clockwise direction; a “)” if there is a gear turning in the counter-clockwise direction, an uppercase “F” if there is a gear that is free and an uppercase “B” if there is a blocked gear.

Sample Input
4 3
...
.*.
.I.
...
4 4
....
.**.
.I..
..*.
0 0

Sample Output
...
.).
.(.
...

....
.BB.
.B..
..F.

1个回答

caozhy
caozhy   Ds   Rxr 2017.09.17 22:41
已采纳
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!
其他相关推荐
laravel 5.2路由学习web中间件back()的问题
laravel高版本添加了middlware的这个用于校验和获取和设置session的这个东西 'web' => [ \App\Http\Middleware\EncryptCookies::class, \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
vector的back()函数
stl中vector的back()函数 返回最后一个元素,如: commentPtr &comment = comments.back().
AC back function on BISO
AC back function(外部断电的情况,电源恢复时的系统状态选择) 一、Where to find the function; BIOS-> Power Management Setup -> ACBack Function 二、How to access BIOS Access BIOS Setup Utility Menus 1. Power-on or
IntelliJ IDEA 13的back/forward
环境:ubuntu14.04 从eclipse转过来。在eclipse有back to和forward to两个图标,可以返回之前的模块,也可以进入之前退出的。 这两个对应的功能也有快捷键。 但是idea的百度不到,谷歌了下,找到了。 里面说idea13已经有了,让它显示出来就行了: View->Toolbar,然后就可以看到了。不过快捷键暂时没找到 来源:http://stack
postfix "loops back to myself"
我们客户公司(infor-trans.com)的邮件发不进我们公司邮箱(cn-gd.uc.com.tw),他们管理员传给我的maillog如下: maillog: Mar  5 10:02:51 mail postfix/smtp[9752]: ACB5812A2DF: to=sales2@cn-gd.uc.com.tw>, relay=127.0.0.1[127.0.0.1]:10025,
std::string 不支持back
string  s = "abc"; if ( s.back() == 'c' )  .... 编译报错, 不支持back, 但用VS2010就没事 后来发现, string的back/front是c++11才加进去的, 所以gcc4.4不行 于是gcc4.9, 发现也不行, 必须加 -std=c++11才行
输入appid以后直接弹出rolling back the update
删除掉server目录下的.appcfg_cookies
非常实用的Go Back N可靠传输协议的演示
这是一个美国大学生做的网络可靠传输协议的示例,Go Back N. 超级实用。用Java applet编程,有原理介绍,报告,源程序。学网络的同学不可不看。
7.Laravel中back()-with($s)前台取不到值
2016.08.03 1.问题描述 在做登录页面时,当验证用户输入错误,返回上一个界面,同时传递错误信息时使用 return back()->with('msg','验证码错误');重定向至前一个页面,但传入的值用session('msg')无法取到 2.解决过程 项目路由配置时,所有路由是配置在一个总的路由分组中,对这个分组添加了web中间件。删掉这个中
Back Track5 学习笔记一
1.BT5默认用户名:root.密码:toor(公司是yeslabccies) 2.进入图形化界面命令:startx 3.更改密码:sudo passwd root 扫描工具 第一部分网络配置: 4.网络配置文件有两个: /etc/network/interfaces 和 /etc/resolv.conf 前一个存放网卡接口、IP、子网掩码等,后一个主要是存放DNS。 5.查看