当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

4031:Journey

题目描述
There is a robot who lives on a cartesian plane and likes to walk around it. One day he planned a very interesting journey around the plane. To make that journey he developed a program which he is going to follow. The program consists of n functions: f1, f2, ..., fn. The i-th function fi is a sequence of ci commands. Each command is of one of the following types:

  • GO: Move forward one meter;

  • LEFT: Turn 90 degrees to the left;

  • RIGHT: Turn 90 degrees to the right;

  • Fk: Follow the instructions of the function fk, then continue following the instructions of the current function.


The robot starts the journey at his home located at the point with coordinates (0, 0) following the instructions of the function f1.

For example, consider the following set of functions:



f1: GO F2 GO F2 GO F2
f2: F3 F3 F3 F3
f3: GO LEFT

The robot’s journey for that case is shown on the picture.

In some cases the journey of the robot might never end. Consider for example the set of instructions consisting of one function f1 that has the following commands: GO F1. In that case the robot keeps going forward and never stops.

The question that puzzles the robot now is how far from the home will he get during his journey. That is, consider the set of all points which the robot will visit. Find the maximum value of |x|+|y| among all those points. If there are points on the path of the robot with arbitrarily large values of |x|+|y|, output “Infinity”.
输入解释
The first line of the input file consists of an integer number n (1 ≤ n ≤ 100). The following n lines contain a description of the functions. The i-th line describes function fi. It consists of the number ci (1 ≤ ci ≤ 100) — the number of commands for function fi, followed by a description of each command.
输出解释
Output the maximum value of |x| + |y| among all points visited during the journey or “Infinity”.
输入样例
Sample Input #1

3
6 GO F2 GO F2 GO F2
4 F3 F3 F3 F3
2 GO LEFT


Sample Input #2

1
2 GO F1


Sample Input #3

4
2 GO F2
7 LEFT GO GO GO F3 LEFT F4
5 GO F4 RIGHT F2 RIGHT
7 GO GO LEFT LEFT GO LEFT GO
输出样例
Sample Output #1

5


Sample Output #2

Infinity


Sample Output #3

13

该题目是Virtual Judge题目,来自 北京大学POJ

源链接: POJ-4031

最后修改于 2020-10-28T15:08:33+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
1000 65536