1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-10-12 17:05:15 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
Files
leetcode-problemset/leetcode-cn/problem (Chinese)/兰顿蚂蚁 [langtons-ant-lcci].html
2025-09-29 14:43:44 +08:00

45 lines
1.4 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<p>一只蚂蚁坐在由白色和黑色方格构成的无限网格上。开始时,网格全白,蚂蚁面向右侧。每行走一步,蚂蚁执行以下操作。</p>
<p>(1) 如果在白色方格上,则翻转方格的颜色,向右(顺时针)转 90 度,并向前移动一个单位。<br />
(2) 如果在黑色方格上,则翻转方格的颜色,向左(逆时针方向)转 90 度,并向前移动一个单位。</p>
<p>编写程序来模拟蚂蚁执行的前 K 个动作,并返回最终的网格。</p>
<p>网格由数组表示,每个元素是一个字符串,代表网格中的一行,黑色方格由&nbsp;<code>'X'</code>&nbsp;表示,白色方格由&nbsp;<code>'_'</code>&nbsp;表示,蚂蚁所在的位置由&nbsp;<code>'L'</code>, <code>'U'</code>, <code>'R'</code>, <code>'D'</code>&nbsp;表示,分别表示蚂蚁&nbsp;左、上、右、下 的朝向。只需要返回能够包含蚂蚁走过的所有方格的最小矩形。</p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>0
<strong>输出:</strong>["R"]
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>2
<strong>输出:
</strong>[
&nbsp; "_X",
&nbsp; "LX"
]
</pre>
<p><strong>示例 3</strong></p>
<pre>
<strong>输入:</strong>5
<strong>输出:
</strong>[
&nbsp; "_U",
&nbsp; "X_",
&nbsp; "XX"
]
</pre>
<p><strong>说明:</strong></p>
<ul>
<li><code>K &lt;= 100000</code></li>
</ul>