G. The Special King

Codeforces
IDCF10215G
Time1000ms
Memory256MB
Difficulty
English · Original
Formal · Original
Assem bought a new chess board that has a special king that move in a different way than other regular kings. In one move, the special king can move from its position in one of the following directions: up, down, left, or right. Formally, if the special king is standing on position ($x$, $y$), in one move it can go to one of the following positions: ($x -1$, $y$), ($x + 1$, $y$), ($x$, $y -1$), or ($x$, $y + 1$). Initially, the special king is standing on position ($x_1$, $y_1$) and Assem wants to place it on position ($x_2$, $y_2$). Can you help Assem by calculating the minimum number of required moves he needs to accomplish his goal? The first line contains an integer $T$ ($1 <= T <= 4096$) specifying the number of test cases, Each test consists of a single line containing four integers $x_1$, $y_1$, $x_2$, and $y_2$ ($1 <= x_1, y_1, x_2, y_2 <= 8$), in which $x_1$ and $y_1$ are representing the starting position of the special king, and $x_2$ and $y_2$ are representing the the ending position. For each test case, print a single line containing the minimum number of required moves to move the special king from the starting position to the ending position. In the first test case, the special king needs to be moved from position ($1$, $3$) to ($4$, $2$). One possible solution is to make $3$ moves down to position ($4$, $3$), then make $1$ move to the left to position ($4$, $2$). So, the total number of moves is $4$. ## Input The first line contains an integer $T$ ($1 <= T <= 4096$) specifying the number of test cases,Each test consists of a single line containing four integers $x_1$, $y_1$, $x_2$, and $y_2$ ($1 <= x_1, y_1, x_2, y_2 <= 8$), in which $x_1$ and $y_1$ are representing the starting position of the special king, and $x_2$ and $y_2$ are representing the the ending position. ## Output For each test case, print a single line containing the minimum number of required moves to move the special king from the starting position to the ending position. [samples] ## Note In the first test case, the special king needs to be moved from position ($1$, $3$) to ($4$, $2$). One possible solution is to make $3$ moves down to position ($4$, $3$), then make $1$ move to the left to position ($4$, $2$). So, the total number of moves is $4$.
**Definitions** Let $ T \in \mathbb{Z} $ be the number of test cases. For each test case $ k \in \{1, \dots, T\} $, let $ (x_{1,k}, y_{1,k}) $ be the starting position and $ (x_{2,k}, y_{2,k}) $ be the target position. **Constraints** 1. $ 1 \le T \le 4096 $ 2. For each $ k \in \{1, \dots, T\} $: $ 1 \le x_{1,k}, y_{1,k}, x_{2,k}, y_{2,k} \le 8 $ **Objective** For each test case $ k $, compute the minimum number of moves required for the king to move from $ (x_{1,k}, y_{1,k}) $ to $ (x_{2,k}, y_{2,k}) $ using only unit steps in the four cardinal directions: $$ \text{min moves}_k = |x_{2,k} - x_{1,k}| + |y_{2,k} - y_{1,k}| $$
API Response (JSON)
{
  "problem": {
    "name": "G. The Special King",
    "description": {
      "content": "Assem bought a new chess board that has a special king that move in a different way than other regular kings.  In one move, the special king can move from its position in one of the following directi",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF10215G"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Assem bought a new chess board that has a special king that move in a different way than other regular kings. \n\nIn one move, the special king can move from its position in one of the following directi...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ T \\in \\mathbb{Z} $ be the number of test cases.  \nFor each test case $ k \\in \\{1, \\dots, T\\} $, let $ (x_{1,k}, y_{1,k}) $ be the starting position and $ (x_{2,k}, y_{2,k}) $ b...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments