Codeforces Round #258 (Div. 2) C. Predict Outcome of the Game 水题
C. Predict Outcome of the Game
题目连接:
http://codeforces.com/contest/451/problem/C
Description
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.
Input
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.
Output
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).
Sample Input
5
3 0 0 0
3 3 0 0
6 4 1 0
6 3 3 0
3 3 3 2
Sample Output
yes
yes
yes
no
no
Hint
题意
有三个球队,一共打了n场比赛,其中的k场比赛你没有看,这k场比赛的结果使得第一支队和第二支队伍分数差d1,第二只队伍和第三只队伍分数差d2
现在问你这三支队伍分数可不可能相同。
题解:
暴力枚举那k场比赛的分数情况,其实就只有四种情况。
枚举完之后,让剩下的场次平均分配使得三个相同就好了。
代码
#include<bits/stdc++.h>
using namespace std;
int t;
long long k,n,d1,d2,md;
bool check(long long a,long long b ,long long c)
{
long long s=a+b+c;
if(k<s||(k-s)%3)return false;
long long tmp=n-k-(3*max(max(a,b),c)-s);
if(tmp<0||tmp%3)return false;
return true;
}
int main()
{
scanf("%d",&t);
while(t--)
{
cin>>n>>k>>d1>>d2;
md=max(d1,d2);
if(check(0,d1,d1+d2)||check(d1+d2,d2,0)||check(d1,0,d2)||check(md-d1,md,md-d2))
cout<<"yes"<<endl;
else
cout<<"no"<<endl;
}
}