3001. 捕获黑皇后需要的最少移动次数
题目链接:3001. 捕获黑皇后需要的最少移动次数
代码如下:
class Solution
{
public:int minMovesToCaptureTheQueen(int a, int b, int c, int d, int e, int f){if (a == e && (c != e || !in_between(b, d, f)) ||//车直接攻击到皇后(同一行)b == f && (d != f || !in_between(a, c, e)) ||//车直接攻击到皇后(同一列)c + d == e + f && (a + b != e + f || !in_between(c, a, e)) ||//象直接攻击到皇后c - d == e - f && (a - b != e - f || !in_between(c, a, e))){return 1;}return 2;}private://m在l和r之间bool in_between(int l, int m, int r){return min(l, r) < m && m < max(l, r);}
};