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

建议使用的浏览器:

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

2848:Kindergarten Graduation

Special Judge 特殊评判
题目描述

The WeeOnes Kindergarten has a strange ceremony as part of its graduation: The children line up with the girls on the left and the boys on the right with a single space between the boys and the girls. By making a sequence of the following four moves, the children are to end up with all the boys on the left and all the girls on the right with a single space between the boys and the girls.


Move Operation
Slide left (s) The child to the right of the empty space moves into the empty
space.
Slide right (S) The child to the left of the empty space moves into the empty space.
Hop left (h) The child two spaces to the right of the open space leapfrogs over
the intervening child to the open space.
Hop right (H) The child two spaces to the left of the open space leapfrogs over
the intervening child to the open space.

In each case, the previous position of the child who moved becomes the new open space.

For example, with two girls and two boys we begin with:

GG_BB

the following moves give the desired result:

s: GGB_B
H: G_BGB
S: _GBGB
h: BG_GB
h: BGBG_
S: BGB_G
H: B_BGG
s: BB_GG

The teacher would like this process to end in a reasonable amount of time so the parents can go home (the children are probably willing to do this all day). Write a program which takes as input the numbers of girls and boys (nGirls and nBoys respectively) and finds a sequence of at most (nGirls * nBoys + nGirls + nBoys) moves which takes you from the starting position to the ending position. [Each girl must leapfrog over (or be leapfrogged over by) each boy and, on average, each child must move past the empty space.]

输入解释

The input begins with the number of problems N, (1 ≤ N ≤ 1000), on a line by itself followed by Nproblem instances each on its own line. A problem instance has the form:

probNumber nGirls nBoys

where

probNumber increases sequentially from 1 to N.

nGirls is the number of girls.
nBoys is the number of boys.

There is at least 1 child and at most 24 children in a class.

输出解释

For each problem instance, output the problem number at the beginning of the line then a single space, then the number of moves on a line. On each following line, output the codes for the required moves in order. Each line except the last should have 50 move characters with the remainder, if any, on the final line. The last line of a problem instance result should be a single blank line.

输入样例
3 
1 2 2
2 4 0
3 5 10
输出样例
1 8
sHShhSHs

2 2
HH

3 65
sHShhsHHHShhhhsHHHHHshhhhhsHHHHHshhhhhsHHHHHshhhhh
SHHHHshhhSHHshS
提示

Note:Other solutions are possible; for instance:

  1. ShsHHshS is also a solution to problem 1
  2. SSSS, HSS, etc. are also acceptable answers to problem 2.

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

题目来源 Greater New York 2005

源链接: POJ-2848

最后修改于 2020-10-29T06:45:50+00:00 由爬虫自动更新

共提交 0

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