mirror of
				https://git.wolves.top/wolves/leetcode.git
				synced 2025-11-04 17:26:32 +08:00 
			
		
		
		
	init
This commit is contained in:
		
							
								
								
									
										18
									
								
								24/12/3001.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								24/12/3001.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,18 @@
 | 
			
		||||
#include <algorithm>
 | 
			
		||||
using namespace std;
 | 
			
		||||
int minMovesToCaptureTheQueen(int a, int b, int c, int d, int e, int f) {
 | 
			
		||||
     // 车与皇后处在同一行,且中间没有象
 | 
			
		||||
    if (a == e && (c != a || d <= min(b, f) || d >= max(b, f))) {
 | 
			
		||||
        return 1;
 | 
			
		||||
    }
 | 
			
		||||
    // 车与皇后处在同一列,且中间没有象
 | 
			
		||||
    if (b == f && (d != b || c <= min(a, e) || c >= max(a, e))) {
 | 
			
		||||
        return 1;
 | 
			
		||||
    }
 | 
			
		||||
    // 象、皇后处在同一条对角线,且中间没有车
 | 
			
		||||
    if (abs(c - e) == abs(d - f) && ((c - e) * (b - f) != (a - e) * (d - f) 
 | 
			
		||||
            || a < min(c, e) || a > max(c, e))) {
 | 
			
		||||
        return 1;
 | 
			
		||||
    }
 | 
			
		||||
    return 2;
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user