There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played.
You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each team, instead he thought that absolute difference between number of wins of first and second team will be d1 and that of between second and third team will be d2.
You don't want any of team win the tournament, that is each team should have the same number of wins after n games. That's why you want to know: does there exist a valid tournament satisfying the friend's guess such that no team will win this tournament?
Note that outcome of a match can not be a draw, it has to be either win or loss.
The first line of the input contains a single integer corresponding to number of test cases t (1 ≤ t ≤ 105).
Each of the next t lines will contain four space-separated integers n, k, d1, d2 (1 ≤ n ≤ 1012; 0 ≤ k ≤ n; 0 ≤ d1, d2 ≤ k) — data for the current test case.
For each test case, output a single line containing either "yes" if it is possible to have no winner of tournament, or "no" otherwise (without quotes).
5 3 0 0 0 3 3 0 0 6 4 1 0 6 3 3 0 3 3 3 2
yes yes yes no no
Sample 1. There has not been any match up to now (k = 0, d1 = 0, d2 = 0). If there will be three matches (1-2, 2-3, 3-1) and each team wins once, then at the end each team will have 1 win.
Sample 2. You missed all the games (k = 3). As d1 = 0 and d2 = 0, and there is a way to play three games with no winner of tournament (described in the previous sample), the answer is "yes".
Sample 3. You missed 4 matches, and d1 = 1, d2 = 0. These four matches can be: 1-2 (win 2), 1-3 (win 3), 1-2 (win 1), 1-3 (win 1). Currently the first team has 2 wins, the second team has 1 win, the third team has 1 win. Two remaining matches can be: 1-2 (win 2), 1-3 (win 3). In the end all the teams have equal number of wins (2 wins).
题意:有三个球队进行了N场比赛,其中K场已经比完了,但是你不知道结果。各自胜场的绝对值,比如一队和二队胜场差是d1,二队和三队胜场差是d2.问比完所有N场比赛是否存在各自都打平了。哈哈
题解:根据他们的两个胜场差d1,d2可以求出他们各自的胜场。但是因为d1,d2是绝对值,所以我们有四种情况需要考虑,比如(+d1,+d2).(+d1,-d2),(-d1,+d2),(-d1,-d2)判断他们是否符合已踢完K场的条件,是否剩下的场数能够使他们打平。嗯,就是这样,注意这几个条件如何去判断即可。
#include <bits/stdc++.h>
using namespace std;
#define LL __int64
int main()
{
LL n,m,d1,d2,T;
scanf("%I64d",&T);
while (T--)
{
scanf("%I64d %I64d %I64d %I64d",&n,&m,&d1,&d2);
// cout<<d1<<d2<<endl;
LL s,d,s1,s2,s3,D1,D2,d3,k=n-m;
d=m-(d1+d2+d2);
s=k-2*d1-d2;
D1=m-(d1+d2);
s1=k-(max(d1,d2)+abs(d1-d2));
D2=m-(max(d1,d2)+abs(d1-d2));
s2=k-(d1+d2);
d3=m-(2*d1+d2);
s3=k-d2*2-d1;
if ((s % 3==0 && s>=0) && (d>=0 && d % 3==0))
puts("yes");
else if ((s1 % 3==0 && s1>=0) && (D1>=0 && D1 % 3==0))
puts("yes");
else if ((s2 % 3==0 && s2>=0) && (D2>=0 && D2 % 3==0))
puts("yes");
else if ((s3 % 3==0 && s3>=0) && (d3>=0 && d3 % 3==0))
puts("yes");
else puts("no");
}
return 0;
}

探讨如何通过朋友对已进行比赛胜负差距的猜测来判断是否存在一种可能,使得三支队伍在全部比赛结束后胜场相同,实现赛局平手的情况。
1334





