CF1612A.Distance
入门
通过率:0%
时间限制:3.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Let's denote the Manhattan distance between two points p1 (with coordinates (x1,y1)) and p2 (with coordinates (x2,y2)) as d(p1,p2)=∣x1−x2∣+∣y1−y2∣. For example, the distance between two points with coordinates (1,3) and (4,2) is ∣1−4∣+∣3−2∣=4.
You are given two points, A and B. The point A has coordinates (0,0), the point B has coordinates (x,y).
Your goal is to find a point C such that:
- both coordinates of C are non-negative integers;
- d(A,C)=2d(A,B) (without any rounding);
- d(B,C)=2d(A,B) (without any rounding).
Find any point C that meets these constraints, or report that no such point exists.
我们用曼哈顿距离表示两点 p1(坐标为 (x1,y1))与 p2(坐标为 (x2,y2))之间的距离:
d(p1,p2)=∣x1−x2∣+∣y1−y2∣
例如,坐标分别为 (1,3) 和 (4,2) 的两点之间的距离为 ∣1−4∣+∣3−2∣=4。
给定两点 A 和 B,其中点 A 的坐标为 (0,0),点 B 的坐标为 (x,y)。
你的目标是找出一个点 C,满足以下条件:
- C 的两个坐标均为非负整数;
- d(A,C)=2d(A,B)(不进行任何舍入);
- d(B,C)=2d(A,B)(不进行任何舍入)。
请找出任意一个满足上述约束的点 C;若不存在这样的点,则报告无解。
输入格式
The first line contains one integer t (1≤t≤3000) — the number of test cases.
Each test case consists of one line containing two integers x and y (0≤x,y≤50) — the coordinates of the point B.
第一行包含一个整数 t(1≤t≤3000)——测试用例的数量。
每个测试用例由一行组成,包含两个整数 x 和 y(0≤x,y≤50)——点 B 的坐标。
输出格式
For each test case, print the answer on a separate line as follows:
- if it is impossible to find a point C meeting the constraints, print "-1 -1" (without quotes);
- otherwise, print two non-negative integers not exceeding 106 — the coordinates of point C 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 106 that meets the constraints.
对于每个测试用例,在单独一行中输出答案,规则如下:
- 如果无法找到满足约束条件的点 C,则输出
\-1 -1(不带引号); - 否则,输出两个不超过 106 的非负整数——即满足约束条件的点 C 的坐标。若存在多个满足条件的答案,输出任意一个即可。可以证明:只要存在满足条件的点,就一定存在坐标均不超过 106 的点满足约束条件。
输入输出样例
输入#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 B has coordinates (49,3). If the point C has coordinates (23,3), then the distance from A to B is ∣49−0∣+∣3−0∣=52, the distance from A to C is ∣23−0∣+∣3−0∣=26, and the distance from B to C is ∣23−49∣+∣3−3∣=26.
- In the second test case, the point B has coordinates (2,50). If the point C has coordinates (1,25), then the distance from A to B is ∣2−0∣+∣50−0∣=52, the distance from A to C is ∣1−0∣+∣25−0∣=26, and the distance from B to C is ∣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 B has coordinates (42,0). If the point C has coordinates (21,0), then the distance from A to B is ∣42−0∣+∣0−0∣=42, the distance from A to C is ∣21−0∣+∣0−0∣=21, and the distance from B to C is ∣21−42∣+∣0−0∣=21.
示例中部分测试用例的解释:
- 在第一个测试用例中,点 B 的坐标为 (49,3)。若点 C 的坐标为 (23,3),则 A 到 B 的距离为 ∣49−0∣+∣3−0∣=52,A 到 C 的距离为 ∣23−0∣+∣3−0∣=26,B 到 C 的距离为 ∣23−49∣+∣3−3∣=26。
- 在第二个测试用例中,点 B 的坐标为 (2,50)。若点 C 的坐标为 (1,25),则 A 到 B 的距离为 ∣2−0∣+∣50−0∣=52,A 到 C 的距离为 ∣1−0∣+∣25−0∣=26,B 到 C 的距离为 ∣1−2∣+∣25−50∣=26。
- 在第三和第四个测试用例中,可以证明不存在满足约束条件的整数坐标点。
- 在第五个测试用例中,点 B 的坐标为 (42,0)。若点 C 的坐标为 (21,0),则 A 到 B 的距离为 ∣42−0∣+∣0−0∣=42,A 到 C 的距离为 ∣21−0∣+∣0−0∣=21,B 到 C 的距离为 ∣21−42∣+∣0−0∣=21。
输入解题思路,AI测评打分。不知道怎么写?