第一行包含一个数字 t (1 <= t <= 10)
接下来的t行每行包括四个数字 n, k, d1, d2(1 <= n <= 10^12; 0 <= k <= n, 0 <= d1, d2 <= k)
每行的比分数据,最终三只球队若能够打平,则输出“yes”,否则输出“no”
2 3 3 0 0 3 3 3 3
yes no
case1: 球队1和球队2 差0分,球队2 和球队3也差0分,所以可能的赛得分是三只球队各得1分
case2: 球队1和球队2差3分,球队2和球队3差3分,所以可能的得分是 球队1得0分,球队2得3分, 球队3 得0分,比赛已经全部结束因此最终不能打平。
#include <iostream> using namespace std; long long t,n,k,d1,d2; int main () { cin>>t; while (t--) { cin>>n>>k>>d1>>d2; if (n % 3 != 0) { cout<<"no"<<endl; continue; } long long a,b,c; a = 0; b = d1; c = b + d2; if (b+c <= k) { long long res = k - b - c; if (res % 3 == 0) { c += res / 3; if (n / 3 >= c) { cout<<"yes"<<endl; continue; } } } c = b - d2; if (c > 0 && b+c <=k) { long long res = k - b - c; if (res % 3 == 0) { b += res / 3; if (n / 3 >= b) { cout<<"yes"<<endl; continue; } } } b = 0; a = d1; c = d2; if (a+c <= k) { long long res = k - a - c; if (res % 3 == 0) { res = res / 3 + max(a,c); if (n / 3 >= res) { cout<<"yes"<<endl; continue; } } } c = 0; b = d2; a = d1 + d2; if (b+a<= k) { long long res = k - b - a; if (res % 3 == 0) { a += res / 3; if (n / 3 >= a) { cout<<"yes"<<endl; continue; } } } a = d2 - d1; if (a > 0 && b+a <=k) { long long res = k - b - a; if (res % 3 == 0) { b += res / 3; if (n / 3 >= b) { cout<<"yes"<<endl; continue; } } } cout<<"no"<<endl; } return 0; }