B. Who‘s Opposite?-Codeforces Round #739 (Div. 3)

原文链接https://codeforces.com/problemset/problem/1560/B

创作不易,你的点赞和收藏都将为我的CF之路点燃火炬,加油,陌生人!

B. Who's Opposite?

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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.

Input

The first line contains one integer tt (1≤t≤1041≤t≤104) — 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≤a,b,c≤108).

Output

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.

Example

input

Copy

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

output

Copy

8
-1
-1
-1
4
1
-1

Note

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.

------------------------------------------------------------------------------------------------------------------

首先,如果人数是奇数,画图可以分析,两两相对,最终一定会有人落单,所以必定不能是奇数人。分析偶数人,所谓对视,其实就是分居在直径两侧,之间的距离等于n/2 ,所以根据题目给出a,b对视,按照顺时针排列,距离的二倍就是n,如果a,b,c都在这个范围内,那么n是合理的,反之,输出-1,对于c对视的寻找,一个是c+cha,一个是c-cha,如果c+cha<=n那么输出,否则输出c-cha

# include<iostream>
# include<algorithm>
# include<math.h>
# include<cstring>
using namespace std;
#define N 100010
typedef long long int ll;

int main()
{

    int t;
    cin>>t;

   
    while(t--)
    {
        int a,b,c;
        cin>>a>>b>>c;

        int cha=abs(b-a);
        int n=cha*2;
        if(!(a<=n&&b<=n&&c<=n))
        {
            cout<<-1<<endl;
        }
        else
          {

             if(cha+c<=n)
             {
                 cout<<cha+c<<'\n';
             }
             else
             {
                 cout<<c-cha<<'\n';
             }
          }


    }

    return 0;
}

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

qinsanma and Code

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值