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;
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值