CF1612A.Distance

入门

通过率:0%

时间限制:3.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

Let's denote the Manhattan distance between two points p1p_1 (with coordinates (x1,y1)(x_1, y_1)) and p2p_2 (with coordinates (x2,y2)(x_2, y_2)) as d(p1,p2)=∣x1−x2∣+∣y1−y2∣d(p_1, p_2) = |x_1 - x_2| + |y_1 - y_2|. For example, the distance between two points with coordinates (1,3)(1, 3) and (4,2)(4, 2) is ∣1−4∣+∣3−2∣=4|1 - 4| + |3 - 2| = 4.

You are given two points, AA and BB. The point AA has coordinates (0,0)(0, 0), the point BB has coordinates (x,y)(x, y).

Your goal is to find a point CC such that:

  • both coordinates of CC are non-negative integers;
  • d(A,C)=d(A,B)2d(A, C) = \dfrac{d(A, B)}{2} (without any rounding);
  • d(B,C)=d(A,B)2d(B, C) = \dfrac{d(A, B)}{2} (without any rounding).

Find any point CC that meets these constraints, or report that no such point exists.

我们用曼哈顿距离表示两点 p1p_1(坐标为 (x1,y1)(x_1, y_1))与 p2p_2(坐标为 (x2,y2)(x_2, y_2))之间的距离:

d(p1,p2)=∣x1−x2∣+∣y1−y2∣d(p_1, p_2) = |x_1 - x_2| + |y_1 - y_2|

例如,坐标分别为 (1,3)(1, 3) 和 (4,2)(4, 2) 的两点之间的距离为 ∣1−4∣+∣3−2∣=4|1 - 4| + |3 - 2| = 4。

给定两点 AA 和 BB,其中点 AA 的坐标为 (0,0)(0, 0),点 BB 的坐标为 (x,y)(x, y)。

你的目标是找出一个点 CC,满足以下条件:

  • CC 的两个坐标均为非负整数;
  • d(A,C)=d(A,B)2d(A, C) = \dfrac{d(A, B)}{2}(不进行任何舍入);
  • d(B,C)=d(A,B)2d(B, C) = \dfrac{d(A, B)}{2}(不进行任何舍入)。

请找出任意一个满足上述约束的点 CC;若不存在这样的点,则报告无解。

输入格式

The first line contains one integer tt (1≤t≤30001 \le t \le 3000) — the number of test cases.

Each test case consists of one line containing two integers xx and yy (0≤x,y≤500 \le x, y \le 50) — the coordinates of the point BB.

第一行包含一个整数 tt(1≤t≤30001 \le t \le 3000)——测试用例的数量。

每个测试用例由一行组成,包含两个整数 xx 和 yy(0≤x,y≤500 \le x, y \le 50)——点 BB 的坐标。

输出格式

For each test case, print the answer on a separate line as follows:

  • if it is impossible to find a point CC meeting the constraints, print "-1 -1" (without quotes);
  • otherwise, print two non-negative integers not exceeding 10610^6 — the coordinates of point CC meeting the constraints. If there are multiple answers, print any of them. It can be shown that if any such point exists, it's possible to find a point with coordinates not exceeding 10610^6 that meets the constraints.

对于每个测试用例,在单独一行中输出答案,规则如下:

  • 如果无法找到满足约束条件的点 CC,则输出 \-1 -1(不带引号);
  • 否则,输出两个不超过 10610^6 的非负整数——即满足约束条件的点 CC 的坐标。若存在多个满足条件的答案,输出任意一个即可。可以证明:只要存在满足条件的点,就一定存在坐标均不超过 10610^6 的点满足约束条件。

输入输出样例

  • 输入#1

    10
    49 3
    2 50
    13 0
    0 41
    42 0
    0 36
    13 37
    42 16
    42 13
    0 0

    输出#1

    23 3
    1 25
    -1 -1
    -1 -1
    21 0
    0 18
    13 12
    25 4
    -1 -1
    0 0

说明/提示

Explanations for some of the test cases from the example:

  • In the first test case, the point BB has coordinates (49,3)(49, 3). If the point CC has coordinates (23,3)(23, 3), then the distance from AA to BB is ∣49−0∣+∣3−0∣=52|49 - 0| + |3 - 0| = 52, the distance from AA to CC is ∣23−0∣+∣3−0∣=26|23 - 0| + |3 - 0| = 26, and the distance from BB to CC is ∣23−49∣+∣3−3∣=26|23 - 49| + |3 - 3| = 26.
  • In the second test case, the point BB has coordinates (2,50)(2, 50). If the point CC has coordinates (1,25)(1, 25), then the distance from AA to BB is ∣2−0∣+∣50−0∣=52|2 - 0| + |50 - 0| = 52, the distance from AA to CC is ∣1−0∣+∣25−0∣=26|1 - 0| + |25 - 0| = 26, and the distance from BB to CC is ∣1−2∣+∣25−50∣=26|1 - 2| + |25 - 50| = 26.
  • In the third and the fourth test cases, it can be shown that no point with integer coordinates meets the constraints.
  • In the fifth test case, the point BB has coordinates (42,0)(42, 0). If the point CC has coordinates (21,0)(21, 0), then the distance from AA to BB is ∣42−0∣+∣0−0∣=42|42 - 0| + |0 - 0| = 42, the distance from AA to CC is ∣21−0∣+∣0−0∣=21|21 - 0| + |0 - 0| = 21, and the distance from BB to CC is ∣21−42∣+∣0−0∣=21|21 - 42| + |0 - 0| = 21.

示例中部分测试用例的解释:

  • 在第一个测试用例中,点 BB 的坐标为 (49,3)(49, 3)。若点 CC 的坐标为 (23,3)(23, 3),则 AA 到 BB 的距离为 ∣49−0∣+∣3−0∣=52|49 - 0| + |3 - 0| = 52,AA 到 CC 的距离为 ∣23−0∣+∣3−0∣=26|23 - 0| + |3 - 0| = 26,BB 到 CC 的距离为 ∣23−49∣+∣3−3∣=26|23 - 49| + |3 - 3| = 26。
  • 在第二个测试用例中,点 BB 的坐标为 (2,50)(2, 50)。若点 CC 的坐标为 (1,25)(1, 25),则 AA 到 BB 的距离为 ∣2−0∣+∣50−0∣=52|2 - 0| + |50 - 0| = 52,AA 到 CC 的距离为 ∣1−0∣+∣25−0∣=26|1 - 0| + |25 - 0| = 26,BB 到 CC 的距离为 ∣1−2∣+∣25−50∣=26|1 - 2| + |25 - 50| = 26。
  • 在第三和第四个测试用例中,可以证明不存在满足约束条件的整数坐标点。
  • 在第五个测试用例中,点 BB 的坐标为 (42,0)(42, 0)。若点 CC 的坐标为 (21,0)(21, 0),则 AA 到 BB 的距离为 ∣42−0∣+∣0−0∣=42|42 - 0| + |0 - 0| = 42,AA 到 CC 的距离为 ∣21−0∣+∣0−0∣=21|21 - 0| + |0 - 0| = 21,BB 到 CC 的距离为 ∣21−42∣+∣0−0∣=21|21 - 42| + |0 - 0| = 21。

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

首页