原题链接:CF1560B
题意
有一个有n个人组成的环(n为偶数),已知a、b两人相对,求与c相对的人的编号。
思路
由题意,易知a与b之差的绝对值为 n / 2 n/2 n/2,与c相对的人与c之差也为 n / 2 n/2 n/2,只需将n求出即可。
代码
#include <bits/stdc++.h>
using namespace std;
void solve(){
int a, b, c;
cin >> a >> b >> c;
int n = abs(a - b);
n *= 2;
//若a, b, c不在圈内,则n不满足题意
if(a > n || b > n || c > n){
cout << -1 << endl;
}
else{
int ans = c + n/2;
if(ans > n){
ans %= n;
}
cout << ans << endl;
}
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("1.in","r",stdin);
#endif
int tt;
cin >> tt;
while(tt--){
solve();
}
return 0;
}