mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-10 18:48:13 +08:00
55 lines
5.1 KiB
HTML
55 lines
5.1 KiB
HTML
<p>在一个 8 x 8 的棋盘上,有一个白色的车(<code>Rook</code>),用字符 <code>'R'</code> 表示。棋盘上还可能存在空方块,白色的象(<code>Bishop</code>)以及黑色的卒(<code>pawn</code>),分别用字符 <code>'.'</code>,<code>'B'</code> 和 <code>'p'</code> 表示。不难看出,大写字符表示的是白棋,小写字符表示的是黑棋。</p>
|
||
|
||
<p>车按国际象棋中的规则移动。东,西,南,北四个基本方向任选其一,然后一直向选定的方向移动,直到满足下列四个条件之一:</p>
|
||
|
||
<ul>
|
||
<li>棋手选择主动停下来。</li>
|
||
<li>棋子因到达棋盘的边缘而停下。</li>
|
||
<li>棋子移动到某一方格来捕获位于该方格上敌方(黑色)的卒,停在该方格内。</li>
|
||
<li>车不能进入/越过已经放有其他友方棋子(白色的象)的方格,停在友方棋子前。</li>
|
||
</ul>
|
||
|
||
<p>你现在可以控制车移动一次,请你统计有多少敌方的卒处于你的捕获范围内(即,可以被一步捕获的棋子数)。</p>
|
||
|
||
<p> </p>
|
||
|
||
<p><strong>示例 1:</strong></p>
|
||
|
||
<p><img alt="" src="https://assets.leetcode-cn.com/aliyun-lc-upload/uploads/2019/02/23/1253_example_1_improved.PNG" style="height: 305px; width: 300px;"></p>
|
||
|
||
<pre><strong>输入:</strong>[[".",".",".",".",".",".",".","."],[".",".",".","p",".",".",".","."],[".",".",".","R",".",".",".","p"],[".",".",".",".",".",".",".","."],[".",".",".",".",".",".",".","."],[".",".",".","p",".",".",".","."],[".",".",".",".",".",".",".","."],[".",".",".",".",".",".",".","."]]
|
||
<strong>输出:</strong>3
|
||
<strong>解释:
|
||
</strong>在本例中,车能够捕获所有的卒。
|
||
</pre>
|
||
|
||
<p><strong>示例 2:</strong></p>
|
||
|
||
<p><img alt="" src="https://assets.leetcode-cn.com/aliyun-lc-upload/uploads/2019/02/23/1253_example_2_improved.PNG" style="height: 306px; width: 300px;"></p>
|
||
|
||
<pre><strong>输入:</strong>[[".",".",".",".",".",".",".","."],[".","p","p","p","p","p",".","."],[".","p","p","B","p","p",".","."],[".","p","B","R","B","p",".","."],[".","p","p","B","p","p",".","."],[".","p","p","p","p","p",".","."],[".",".",".",".",".",".",".","."],[".",".",".",".",".",".",".","."]]
|
||
<strong>输出:</strong>0
|
||
<strong>解释:
|
||
</strong>象阻止了车捕获任何卒。
|
||
</pre>
|
||
|
||
<p><strong>示例 3:</strong></p>
|
||
|
||
<p><img alt="" src="https://assets.leetcode-cn.com/aliyun-lc-upload/uploads/2019/02/23/1253_example_3_improved.PNG" style="height: 305px; width: 300px;"></p>
|
||
|
||
<pre><strong>输入:</strong>[[".",".",".",".",".",".",".","."],[".",".",".","p",".",".",".","."],[".",".",".","p",".",".",".","."],["p","p",".","R",".","p","B","."],[".",".",".",".",".",".",".","."],[".",".",".","B",".",".",".","."],[".",".",".","p",".",".",".","."],[".",".",".",".",".",".",".","."]]
|
||
<strong>输出:</strong>3
|
||
<strong>解释: </strong>
|
||
车可以捕获位置 b5,d6 和 f5 的卒。
|
||
</pre>
|
||
|
||
<p> </p>
|
||
|
||
<p><strong>提示:</strong></p>
|
||
|
||
<ol>
|
||
<li><code>board.length == board[i].length == 8</code></li>
|
||
<li><code>board[i][j]</code> 可以是 <code>'R'</code>,<code>'.'</code>,<code>'B'</code> 或 <code>'p'</code></li>
|
||
<li>只有一个格子上存在 <code>board[i][j] == 'R'</code></li>
|
||
</ol>
|