CF1904A.Forked!

入门

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Lunchbox is done with playing chess! His queen and king just got forked again!

In chess, a fork is when a knight attacks two pieces of higher value, commonly the king and the queen. Lunchbox knows that knights can be tricky, and in the version of chess that he is playing, knights are even trickier: instead of moving 11 tile in one direction and 22 tiles in the other, knights in Lunchbox's modified game move aa tiles in one direction and bb tiles in the other.

Lunchbox is playing chess on an infinite chessboard which contains all cells (x,y)(x,y) where xx and yy are (possibly negative) integers. Lunchbox's king and queen are placed on cells (xK,yK)(x_K,y_K) and (xQ,yQ)(x_Q,y_Q) respectively. Find the number of positions such that if a knight was placed on that cell, it would attack both the king and queen.

午餐盒已经玩腻国际象棋了!他的皇后和国王又一次被马(骑士)同时攻击了!

在国际象棋中,“双将”(fork)是指一匹马同时攻击两个价值更高的棋子,通常是国王和皇后。午餐盒知道马的走法很棘手;而在他所玩的这版国际象棋中,马的走法更加棘手:它不再按常规走法——即在一个方向上走 11 格、另一方向上走 22 格——而是改为在一个方向上走 aa 格、另一方向上走 bb 格。

午餐盒正在一个无限大的棋盘上下棋,该棋盘包含所有坐标为 (x,y)(x,y) 的格子,其中 xx 和 yy 均为(可能为负的)整数。午餐盒的国王与皇后分别位于格子 (xK,yK)(x_K,y_K) 和 (xQ,yQ)(x_Q,y_Q) 上。求满足如下条件的格子数量:若将一匹马置于该格子上,则它能同时攻击国王与皇后。

输入格式

Each test contains multiple test cases. The first line contains an integer tt (1≤t≤10001 \leq t \leq 1000) — the number of test cases. The description of the test cases follows.

The first line of each test case contains two integers aa and bb (1≤a,b≤1081 \le a, b \le 10^8) — describing the possible moves of the knight.

The second line of each test case contains two integers xKx_K and yKy_K (0≤xK,yK≤1080 \le x_K, y_K \le 10^8) — the position of Lunchbox's king.

The third line in a test case contains xQx_Q and yQy_Q (0≤xQ,yQ≤1080 \le x_Q, y_Q \le 10^8) — the position of Lunchbox's queen.

It is guaranteed that Lunchbox's queen and king will occupy different cells. That is, (xK,yK)≠(xQ,yQ)(x_K,y_K) \neq (x_Q,y_Q).

每个测试包含多个测试用例。第一行包含一个整数 tt(1≤t≤10001 \leq t \leq 1000),表示测试用例的数量。随后是各测试用例的描述。

每个测试用例的第一行包含两个整数 aa 和 bb(1≤a,b≤1081 \le a, b \le 10^8),表示骑士可能的移动方式。

每个测试用例的第二行包含两个整数 xKx_K 和 yKy_K(0≤xK,yK≤1080 \le x_K, y_K \le 10^8),表示 Lunchbox 的国王的位置。

每个测试用例的第三行包含 xQx_Q 和 yQy_Q(0≤xQ,yQ≤1080 \le x_Q, y_Q \le 10^8),表示 Lunchbox 的皇后的位置。

保证 Lunchbox 的皇后与国王占据不同的格子,即 (xK,yK)≠(xQ,yQ)(x_K,y_K) \neq (x_Q,y_Q)。

输出格式

For each test case, output the number of positions on an infinite chessboard such that a knight can attack both the king and the queen.

对于每个测试用例,输出在无限棋盘上能够同时攻击国王和皇后的方格位置数量。

输入输出样例

  • 输入#1

    4
    2 1
    0 0
    3 3
    1 1
    3 1
    1 3
    4 4
    0 0
    8 0
    4 2
    1 4
    3 4

    输出#1

    2
    1
    2
    0

说明/提示

In the first test case, the knight can move 2 squares in one direction and 1 square in the other (it is essentially the same as the knight in standard chess). A knight placed on (2,1)(2, 1) or (1,2)(1, 2) would attack both the king and queen.

Example of a knight placement that forks the queen and king in the first test case. The squares that the knight attacks are highlighted in red.

In the second test case, a knight placed on (2,2)(2, 2) would attack both the king and queen.

Example of a knight placement that does not fork the queen and king in the second test case. The knight attacks the king but not the queen.

In the third test case, a knight placed on (4,4)(4, 4) or (4,−4)(4, -4) would attack both the king and queen.

In the fourth test case, there are no positions where the knight can attack both the king and the queen.

(Credits to EnDeRBeaT for the nice images)

在第一个测试用例中,骑士可以沿一个方向移动 2 格,再沿另一方向移动 1 格(这本质上与标准国际象棋中的骑士走法相同)。将骑士放置在 (2,1)(2, 1) 或 (1,2)(1, 2) 处,即可同时攻击国王和皇后。

第一个测试用例中一种能同时攻击皇后和国王的骑士摆放示例。骑士可攻击的格子以红色高亮显示。

在第二个测试用例中,将骑士放置在 (2,2)(2, 2) 处即可同时攻击国王和皇后。

第二个测试用例中一种不能同时攻击皇后和国王的骑士摆放示例。该骑士攻击了国王,但未攻击皇后。

在第三个测试用例中,将骑士放置在 (4,4)(4, 4) 或 (4,−4)(4, -4) 处即可同时攻击国王和皇后。

在第四个测试用例中,不存在任何位置使得骑士能够同时攻击国王和皇后。

(感谢 EnDeRBeaT 提供精美的图片)

输入解题思路,AI测评打分。不知道怎么写?

首页