我敢肯定,每个人都可以看到杯子可以堆成金字塔(和其他形状)之前:
A
A A A
A A A A A
A A A A A A A A
是的,A
绝对足够代表杯子。
可以在地面上,结构右侧或两个相邻杯子的顶部添加新杯子。这是上面的结构,但是新杯子的所有可用位置都标有_
:
_ A
A A A
A _ _ A A A A
A A A A A A A A _ _ _
假设我们要建立一个可以组装这些杯子叠的机器人。机器人将了解两条简单的指令来操纵这种结构:
a
:按照从左到右的阅读顺序在第一个可用位置添加一个新杯子(即,从上到下,从左到右扫描行,直到找到可用的位置,然后将杯子放在那里)。上面的示例将变为:A A A A A A A A A A A A A A A A A A
r
:按照从左到右的顺序卸下第一个杯子。上面的示例将变为:A A A A A A A A A A A A A A A A
事实证明,仅使用这两个操作就可以从头开始构建任何结构。例如
A
A A A
A A A A A
可以按照指令顺序构建
aaaaaaaaaaaarrrrraa
可以使用以下示例构建以上较大的示例
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaarrrrrrrrrrrrrrrrrraaaaaaarr
这是更大的一个:
A
A A A
A A A A A A A
A A A A A A A A A A A A
A A A A A A A A A A A A A A A
可以用
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaarrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrraaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaarrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrraaaaaaaaaaaaaaaaaaarrrrrrrrrrrrrrraaaaaaaaaaaaaarrrrrrrrrrraaaaaaaa
注意:如果按照拆卸说明释放了地面上的斑点,在将杯子放置在所有现有杯子的右侧之前,它们将被重新使用。例如
aaaarrra
将产生
A A
不
A A
您可以将地面想象成一排无限长的杯子。
挑战
给定堆叠杯的结构,返回代表构建此结构的说明的序列。您的主要分数是底部提供的测试用例的说明总数。如果出现平局(很可能是这样,因为我确信有效的最佳解决方案是可能的),则以最短的解决方案为准。
以下是有关规则的更多详细信息:
- 您可能假设输入的底行没有前导空格,因此始终使用杯子的最左侧接地点。
- 您可以假定任何合理数量的尾随空格(没有空格,一个空格,填充为矩形,填充为具有单个尾随空格的矩形)。
- 您可以有选择地期望输入以单个尾随换行符结尾。
- 您可以选择任意两个不同的可打印ASCII字符(0x20至0x7E,包括0x20至0x7E),而不是
A
和空格(有关空格的规则然后转移到所选字符)。 - 您的输出应仅包含两个表示操作的不同字符(您可以选择
a
和以外的其他字符r
)。您可以选择打印单个尾随换行符。 - 您的代码必须能够在一台合理的台式PC上在一分钟之内解决下面的任何测试用例(如果我花了两分钟的时间,我会带给您疑问的好处,但是如果花十分钟我会赢了) 't-我相信有可能在不到一秒钟的时间内解决所有问题的最佳算法。
- 您不得针对个别测试用例优化代码(例如,通过对它们进行硬编码)。如果我怀疑有人这样做,我保留更改测试用例的权利。
您可以使用此CJam脚本进行相反的操作:这将花费一串构建说明并打印结果的杯子杯。(感谢Dennis重写了代码段,并显着加快了速度。)
Sp3000还出于相同的目的提供了此替代Python脚本。
测试用例
在每个测试用例之后,都有一个数字,指示根据Ell的答案的最佳指令数。
A
A A
A A A
A A A A
A A A A A
A A A A A A
A A A A A A A
A A A A A A A A
A A A A A A A A A
A A A A A A A A A A
A A A A A A A A A A A
A A A A A A A A A A A A
A A A A A A A A A A A A A
A A A A A A A A A A A A A A
A A A A A A A A A A A A A A A
A A A A A A A A A A A A A A A A
A A A A A A A A A A A A A A A A A
A A A A A A A A A A A A A A A A A A
A A A A A A A A A A A A A A A A A A A
A A A A A A A A A A A A A A A A A A A A
A A A A A A A A A A A A A A A A A A A A A
A A A A A A A A A A A A A A A A A A A A A A
A A A A A A A A A A A A A A A A A A A A A A A
A A A A A A A A A A A A A A A A A A A A A A A A
A A A A A A A A A A A A A A A A A A A A A A A A A
A A A A A A A A A A A A A A A A A A A A A A A A A A
A A A A A A A A A A A A A A A A A A A A A A A A A A A
A A A A A A A A A A A A A A A A A A A A A A A A A A A A
A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
820
A
A A
A A A
A A A A
A A A A A
A A A A A A
A A A A A A A
A A A A A A A A
A A A A A A A A A A
A A A A A A A A A A A A
A A A A A A A A A A A A A A
A A A A A A A A A A A A A A A A
A A A A A A A A A A A A A A A A A A A
A A A A A A A A A A A A A A A A A A A A A A
A A A A A A A A A A A A A A A A A A A A A A A A A A
A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
1946
A
A A
A A A
A A A A
A A A A A
A A A A A A
A A A A A A A
A A A A A A A A
A A A A A A A A A A
A A A A A A A A A A A A
A A A A A A A A A A A A A A
A A A A A A A A A A A A A A A A
A A A A A A A A A A A A A A A A A A A
A A A A A A A A A A A A A A A A A A A A A A
A A A A A A A A A A A A A A A A A A A A A A A A A A
A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
2252
A A
A A A A
A A A A A A
A A A A A A A A
A A A A A A A A A A
A A A A A A A A A A A A
A A A A A A A A A A A A A A
A A A A A A A A A A A A A A A A
A A A A A A A A A A A A A A A A A A
A A A A A A A A A A A A A A A A A A A A
A A A A A A A A A A A A A A A A A A A A A A
A A A A A A A A A A A A A A A A A A A A A A A A
A A A A A A A A A A A A A A A A A A A A A A A A A A
A A A A A A A A A A A A A A A A A A A A A A A A A A A A
A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
9958
A A
A A A A
A A A A A A
A A A A A A A A
A A A A A A A A A A
A A A A A A A A A A A A
A A A A A A A A A A A A A A
A A A A A A A A A A A A A A A A
A A A A A A A A A A A A A A A A A A
A A A A A A A A A A A A A A A A A A A A
A A A A A A A A A A A A A A A A A A A A A A
A A A A A A A A A A A A A A A A A A A A A A A A
A A A A A A A A A A A A A A A A A A A A A A A A A A
A A A A A A A A A A A A A A A A A A A A A A A A A A A A
A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
5540
A A A A A A A A A A A A A A A A A A A A
10280
A A A A A A A A A A A A A A A A A A A A
A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
10320
A A A A A A A A A A
A A A A A A A A A A A A A A A A A A A A
A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
5794
A
A A
A A A
A A A A A
A A A A A A A
A A A A A A A A A A
A A A A A A A A A A A A A
A A A A A A A A A A A A A A A A A A
A A A A A A A A A A A A A A A A A A A A A A A
A A A A A A A A A A A A A A A A A A A A A A A A A A A
A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
3297
A A
A A A
A A A A
A A A A A
A A A A A A
A A A A A A A
A A A A A A A A
A A A A A A A A A
A A A A A A A A A A A
A A A A A A A A A A A A A
A A A A A A A A A A A A A A A A
A A A A A A A A A A A A A A A A A
A A A A A A A A A A A A A A A A A A
A A A A A A A A A A A A A A A A A A A A
A A A A A A A A A A A A A A A A A A A A A A
A A A A A A A A A A A A A A A A A A A A A A A A A A
A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
4081
A
A A A A
A A A A A A A A A
A A A A A A A A A A A A A A A A
A A A A A A A A A A A A A A A A A A A A A A A A
A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
4475
A
A A A A A A A A
A A A A A A A A A A A A A A A A A A A
A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
5752
这意味着,最高可能的分数是64,515条指令。