mirror of
				https://gitee.com/coder-xiaomo/leetcode-problemset
				synced 2025-11-04 11:43:12 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			51 lines
		
	
	
		
			2.2 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			51 lines
		
	
	
		
			2.2 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
<p>现有一个下标从 <strong>1</strong> 开始的 <code>8 x 8</code> 棋盘,上面有 <code>3</code> 枚棋子。</p>
 | 
						||
 | 
						||
<p>给你 <code>6</code> 个整数 <code>a</code> 、<code>b</code> 、<code>c</code> 、<code>d</code> 、<code>e</code> 和 <code>f</code> ,其中:</p>
 | 
						||
 | 
						||
<ul>
 | 
						||
	<li><code>(a, b)</code> 表示白色车的位置。</li>
 | 
						||
	<li><code>(c, d)</code> 表示白色象的位置。</li>
 | 
						||
	<li><code>(e, f)</code> 表示黑皇后的位置。</li>
 | 
						||
</ul>
 | 
						||
 | 
						||
<p>假定你只能移动白色棋子,返回捕获黑皇后所需的<strong>最少</strong>移动次数。</p>
 | 
						||
 | 
						||
<p><strong>请注意</strong>:</p>
 | 
						||
 | 
						||
<ul>
 | 
						||
	<li>车可以向垂直或水平方向移动任意数量的格子,但不能跳过其他棋子。</li>
 | 
						||
	<li>象可以沿对角线方向移动任意数量的格子,但不能跳过其他棋子。</li>
 | 
						||
	<li>如果车或象能移向皇后所在的格子,则认为它们可以捕获皇后。</li>
 | 
						||
	<li>皇后不能移动。</li>
 | 
						||
</ul>
 | 
						||
 | 
						||
<p> </p>
 | 
						||
 | 
						||
<p><strong class="example">示例 1:</strong></p>
 | 
						||
<img alt="" src="https://assets.leetcode.com/uploads/2023/12/21/ex1.png" style="width: 600px; height: 600px; padding: 10px; background: #fff; border-radius: .5rem;" />
 | 
						||
<pre>
 | 
						||
<strong>输入:</strong>a = 1, b = 1, c = 8, d = 8, e = 2, f = 3
 | 
						||
<strong>输出:</strong>2
 | 
						||
<strong>解释:</strong>将白色车先移动到 (1, 3) ,然后移动到 (2, 3) 来捕获黑皇后,共需移动 2 次。
 | 
						||
由于起始时没有任何棋子正在攻击黑皇后,要想捕获黑皇后,移动次数不可能少于 2 次。
 | 
						||
</pre>
 | 
						||
 | 
						||
<p><strong class="example">示例 2:</strong></p>
 | 
						||
<img alt="" src="https://assets.leetcode.com/uploads/2023/12/21/ex2.png" style="width: 600px; height: 600px;padding: 10px; background: #fff; border-radius: .5rem;" />
 | 
						||
<pre>
 | 
						||
<strong>输入:</strong>a = 5, b = 3, c = 3, d = 4, e = 5, f = 2
 | 
						||
<strong>输出:</strong>1
 | 
						||
<strong>解释:</strong>可以通过以下任一方式移动 1 次捕获黑皇后:
 | 
						||
- 将白色车移动到 (5, 2) 。
 | 
						||
- 将白色象移动到 (5, 2) 。
 | 
						||
</pre>
 | 
						||
 | 
						||
<p> </p>
 | 
						||
 | 
						||
<p><strong>提示:</strong></p>
 | 
						||
 | 
						||
<ul>
 | 
						||
	<li><code>1 <= a, b, c, d, e, f <= 8</code></li>
 | 
						||
	<li>两枚棋子不会同时出现在同一个格子上。</li>
 | 
						||
</ul>
 |