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

这题的题意是给你3个数   x,y,z   首先 x对应的是y  其次 让你找出z的对应值 找到输出  没找到输出 -1

#include "bits/stdc++.h"
 
using namespace std;
int t;
int main()
{
    cin >> t;
    while (t--)
    {
        int x,y,z;
        cin >> x >> y >> z;
        int k = abs(x-y);  //假设2个相邻的数字是对立结对是错的 
         // 假设k*2是总区间最大  超出这个范围也是错的 区间小于俩个数的最大值也是错的;
        
        if(k*2<z || k==1 || k*2 < max(x,y)) cout << "-1" << endl;
        else{
            if(z+k <=k*2) cout << z+k << endl;
            else cout << z-k << endl;
        }
    }
 
    return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_53013914/article/details/120104683
今日推荐