CF1560B.Who's Opposite?

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Some number of people (this number is even) have stood in a circle. The people stand in the circle evenly. They are numbered clockwise starting from a person with the number 11. Each person is looking through the circle's center at the opposite person.

A sample of a circle of 66 persons. The orange arrows indicate who is looking at whom.

You don't know the exact number of people standing in the circle (but this number is even, no doubt). It is known that the person with the number aa is looking at the person with the number bb (and vice versa, of course). What is the number associated with a person being looked at by the person with the number cc? If, for the specified aa, bb, and cc, no such circle exists, output -1.

若干人(人数为偶数)围成一个圆圈站立。人们在圆圈上均匀分布。他们从编号为 11 的人开始,按顺时针方向依次编号。每个人均通过圆心注视其正对面的人。

一个由 66 人组成的圆圈示例。橙色箭头表示谁在注视谁。

你并不知道圆圈中确切的人数(但可以确定该人数为偶数)。已知编号为 aa 的人正注视着编号为 bb 的人(反之亦然,显然成立)。那么,编号为 cc 的人所注视的人的编号是多少?若对给定的 aa、bb 和 cc,不存在满足条件的圆圈,则输出 −1-1。

输入格式

The first line contains one integer tt (1≤t≤1041 \le t \le 10^4) — the number of test cases. Then tt test cases follow.

Each test case consists of one line containing three distinct integers aa, bb, cc (1≤a,b,c≤1081 \le a,b,c \le 10^8).

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

每个测试用例由一行组成,包含三个互不相同的整数 aa、bb、cc(1≤a,b,c≤1081 \le a,b,c \le 10^8)。

输出格式

For each test case output in a separate line a single integer dd — the number of the person being looked at by the person with the number cc in a circle such that the person with the number aa is looking at the person with the number bb. If there are multiple solutions, print any of them. Output −1-1 if there's no circle meeting the given conditions.

对于每个测试用例,在单独一行中输出一个整数 dd —— 即在满足“编号为 aa 的人正看着编号为 bb 的人”的圆形排列中,编号为 cc 的人所看着的人的编号。若存在多个解,输出任意一个即可。若不存在满足给定条件的圆形排列,则输出 −1-1。

输入输出样例

  • 输入#1

    7
    6 2 4
    2 3 1
    2 4 10
    5 3 4
    1 3 2
    2 5 4
    4 3 2

    输出#1

    8
    -1
    -1
    -1
    4
    1
    -1

说明/提示

In the first test case, there's a desired circle of 88 people. The person with the number 66 will look at the person with the number 22 and the person with the number 88 will look at the person with the number 44.

In the second test case, there's no circle meeting the conditions. If the person with the number 22 is looking at the person with the number 33, the circle consists of 22 people because these persons are neighbors. But, in this case, they must have the numbers 11 and 22, but it doesn't meet the problem's conditions.

In the third test case, the only circle with the persons with the numbers 22 and 44 looking at each other consists of 44 people. Therefore, the person with the number 1010 doesn't occur in the circle.

在第一个测试用例中,存在一个由 88 人组成的理想圆圈。编号为 66 的人注视编号为 22 的人,编号为 88 的人注视编号为 44 的人。

在第二个测试用例中,不存在满足条件的圆圈。若编号为 22 的人注视编号为 33 的人,则该圆圈仅包含 22 人(因为这两人是相邻的)。但此时,这两人编号必须为 11 和 22,而这不满足题目的条件。

在第三个测试用例中,唯一满足编号为 22 和 44 的两人彼此注视的圆圈由 44 人组成。因此,编号为 1010 的人未出现在该圆圈中。

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

首页