第一行包含一个数字 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分,比赛已经全部结束因此最终不能打平。
// 我都没创建数组,却总是提醒我数组越界 心态爆炸 求好心人解答
import java.util.*;
public class Main{
public static void main(String[] args){
try(Scanner in = new Scanner(System.in)){
int t = in.nextInt(),i = 0;
while(i < t){
long n = in.nextLong();
int k = in.nextInt(),d1 = in.nextInt(),d2 = in.nextInt();
System.out.println(getResult(n,k,d1,d2));
i++;
}
}
}
public static String getResult(long n,int k,int d1,int d2){
int x11 = 0,x12 = 0,x13 = 0,x21 = 0,x22 = 0,x23 = 0,x31 = 0,x32 = 0,x33 = 0,x41 = 0,x42 = 0,x43 = 0;
boolean tag1 = false,tag2 = false,tag3 = false,tag4 = false;
if((k + d2 - d1) / 3 == (k + d2 - d1) / 3.0){
x12 = (k + d2 - d1) / 3;
x11 = d1 + x12;
x13 = x12 - d2;
if(x11 >= x12 && x12 >= x13 && x13 >= 0 && x11 <= k) tag1 = true;
}
if((k - d2 - d1) / 3 == (k - d2 - d1) / 3.0){
x22 = (k - d2 - d1) / 3;
x21 = d1 + x22;
x23 = x22 + d2;
if(x21 >= x22 && x23 >= x22 && x22 >= 0 && x21 <= k && x23 <= k) tag2 = true;
}
if((k + d2 + d1) / 3 == (k + d2 + d1) / 3.0){
x32 = (k + d2 + d1) / 3;
x31 = x32 - d1;
x33 = x32 - d2;
if(x32 >= x31 && x32 >= x33 && x33 >= 0 && x31 >= 0 && x32 <= k) tag3 = true;
}
if((k - d2 + d1) / 3 == (k - d2 + d1) / 3.0){
x42 = (k - d2 + d1) / 3;
x41 = x42 - d1;
x43 = x42 - d2;
if(x42 >= x41 && x43 >= x42 && x41 >= 0 && x43 <= k) tag4 = true;
}
if(tag1){
int max = Math.max(Math.max(x11,x12),x13),c = Math.abs(max - x11) + Math.abs(max - x12) + Math.abs(max - x13);
if(n - k >= c && (n - k - c) % 3 == 0) return "yes";
}
if(tag2){
int max = Math.max(Math.max(x21,x22),x23),c = Math.abs(max - x21) + Math.abs(max - x22) + Math.abs(max - x23);
if(n - k >= c && (n - k - c) % 3 == 0) return "yes";
}
if(tag3){
int max = Math.max(Math.max(x31,x32),x33),c = Math.abs(max - x31) + Math.abs(max - x32) + Math.abs(max - x33);
if(n - k >= c && (n - k - c) % 3 == 0) return "yes";
}
if(tag4){
int max = Math.max(Math.max(x41,x42),x43),c = Math.abs(max - x41) + Math.abs(max - x42) + Math.abs(max - x43);
if(n - k >= c && (n - k - c) % 3 == 0) return "yes";
}
return "no";
}
}