CF2274A.The Projections of Paco

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given nn integers a1,a2,…,ana_1, a_2, \ldots, a_n representing points on a number line. Paco has a token that starts at coordinate 00.

Reflecting the token about a point moves it to the other side of that point, keeping the same distance from it. If the token is already at that point, it stays there.

Paco's token (blue) being reflected about a point (red).

Choose an integer pp. Paco's token is reflected about the points with coordinates p,a1,a2,…,anp, a_1, a_2, \ldots, a_n, in this order, exactly once each.

Help Paco find pp such that his token ends at exactly coordinate 00. This is very important for him. It can be shown that exactly one such integer exists.

给你 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n,它们表示数轴上的若干点。Paco 有一个初始位于坐标 00 处的标记。

关于某一点对标记进行反射,是指将其移动到该点另一侧、且与该点保持相同距离的位置。若标记已位于该点,则其位置保持不变。

Paco 的标记(蓝色)关于某一点(红色)被反射。

请选择一个整数 pp。Paco 的标记将依次、且仅一次地关于坐标为 p,a1,a2,…,anp, a_1, a_2, \ldots, a_n 的点进行反射。

请帮助 Paco 找到满足条件的 pp,使得标记最终恰好落在坐标 00 处。这对 Paco 至关重要。可以证明,满足条件的整数 pp 恰好存在唯一一个。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1041 \le t \le 10^4). The description of the test cases follows.

The first line of each test case contains a single integer nn (1≤n≤1051 \le n \le 10^5).

The second line contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (−104≤ai≤104-10^4 \le a_i \le 10^4).

It is guaranteed that the sum of nn over all test cases does not exceed 10510^5.

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤1041 \le t \le 10^4)。随后是各测试用例的描述。

每个测试用例的第一行包含一个整数 nn(1≤n≤1051 \le n \le 10^5)。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(−104≤ai≤104-10^4 \le a_i \le 10^4)。

保证所有测试用例的 nn 之和不超过 10510^5。

输出格式

For each test case, print the integer pp.

对于每个测试用例,输出整数 pp。

输入输出样例

  • 输入#1

    5
    1
    3
    2
    2 5
    3
    2 7 1
    4
    -3 0 -3 0
    1
    0

    输出#1

    3
    -3
    -4
    -6
    0

说明/提示

In the first test case, choose p=3p=3. Paco's token moves from 00 to 66 and then back to 00.

In the second test case, choose p=−3p=-3. Paco's token visits coordinates 0→−6→10→00 \to -6 \to 10 \to 0.

In the third test case, choose p=−4p=-4. Paco's token visits coordinates 0→−8→12→2→00 \to -8 \to 12 \to 2 \to 0.

在第一个测试用例中,选择 p=3p=3。Paco 的棋子从 00 移动到 66,然后返回 00。

在第二个测试用例中,选择 p=−3p=-3。Paco 的棋子经过的坐标为 0→−6→10→00 \to -6 \to 10 \to 0。

在第三个测试用例中,选择 p=−4p=-4。Paco 的棋子经过的坐标为 0→−8→12→2→00 \to -8 \to 12 \to 2 \to 0。

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

首页