Predict Outcome of the Game

Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

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 kgames. 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

Input
5
3 0 0 0
3 3 0 0
6 4 1 0
6 3 3 0
3 3 3 2
Output
yes
yes
yes
no
no

Hint

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).

 #include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std; int main()
{
int T;
long long n,k,d1,d2;
long long i,j;
scanf("%d",&T);
while(T--)
{
scanf("%I64d %I64d %I64d %I64d",&n,&k,&d1,&d2);
long long x,y,z,c,v,ma; int flg=; v=k-d1-*d2;
if(v>= && v%== && flg==)
{
x=v/+d1+d2,y=v/+d2,z=v/;
if((n-k-(x-y+x-z))>= && (n-k-(x-y+x-z))%==)
flg=;
//if(flg==1)
//printf("%d\n",1);
} v=k-d1+*d2;
if(v>= && v%== && flg==)
{
x=v/+d1-d2,y=v/-d2,z=v/;
if(x>= && y>= && z>=)
{
ma=max(x,y);
ma=max(ma,z);
if((n-k-(ma-x+ma-y+ma-z))>= && (n-k-(ma-x+ma-y+ma-z))%==)
flg=;
}
//if(flg==1)
//printf("%d\n",2);
} v=k+d1-*d2;
if(v>= && v%== && flg==)
{
x=v/-d1+d2,y=v/+d2,z=v/;
if(x>= && y>= && z>=)
{
ma=max(x,y);
ma=max(ma,z);
if((n-k-(ma-x+ma-y+ma-z))>= && (n-k-(ma-x+ma-y+ma-z))%==)
flg=;
}
//if(flg==1)
//printf("%d\n",3);
} v=k+d1+*d2;
if(v>= && v%== && flg==)
{
x=v/-d1-d2,y=v/-d2,z=v/;
if(x>= && y>= && z>=)
{
ma=max(x,y);
ma=max(ma,z);
if((n-k-(ma-x+ma-y+ma-z))>= && (n-k-(ma-x+ma-y+ma-z))%==)
flg=;
}
//if(flg==1)
//printf("%d\n",4);
} if(flg==)
printf("yes\n");
else
printf("no\n");
} }

CodeForces 451C Predict Outcome of the Game的更多相关文章

  1. codeforces 451C. Predict Outcome of the Game 解题报告

    题目链接:http://codeforces.com/problemset/problem/451/C 题目意思:有3支球队(假设编号为1.2.3),总共要打 n 场比赛,已知已经错过这n场比赛中的 ...

  2. codeforces 258div2C Predict Outcome of the Game

    题目链接:http://codeforces.com/contest/451/problem/C 解题报告:三个球队之间一共有n场比赛,现在已经进行了k场,不知道每个球队的胜场是多少,如三个球队的胜场 ...

  3. 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 a ...

  4. CF451C Predict Outcome of the Game 水题

    Codeforces Round #258 (Div. 2) Predict Outcome of the Game C. Predict Outcome of the Game time limit ...

  5. CodeForces 157A Game Outcome

    A. Game Outcome time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...

  6. Codeforces Round #258 (Div. 2/C)/Codeforces451C_Predict Outcome of the Game(枚举)

    解题报告 http://blog.csdn.net/juncoder/article/details/38102391 题意: n场比赛当中k场是没看过的,对于这k场比赛,a,b,c三队赢的场次的关系 ...

  7. cf451C-Predict Outcome of the Game

    http://codeforces.com/problemset/problem/451/C A - Predict Outcome of the Game Time Limit:2000MS     ...

  8. Codeforces Round #258 (Div. 2)[ABCD]

    Codeforces Round #258 (Div. 2)[ABCD] ACM 题目地址:Codeforces Round #258 (Div. 2) A - Game With Sticks 题意 ...

  9. Codeforces Round #258 (Div. 2)

    A - Game With Sticks 题目的意思: n个水平条,m个竖直条,组成网格,每次删除交点所在的行和列,两个人轮流删除,直到最后没有交点为止,最后不能再删除的人将输掉 解题思路: 每次删除 ...

随机推荐

  1. 夺命雷公狗---DEDECMS----20dedecms取出栏目页对应的内容

    取出栏目页对应的内容 现在我们的栏目页面是可以完全正常跳转了,那么我们现在需要完成的就是让他的内容全部(电影,连续剧,综艺)分类的显示出来. 我们还是要使用{dede:arclist}标签来取出我们所 ...

  2. Power Gating的设计(模块)

    Switching Fabric的设计: 三种架构:P沟道的switch vdd(header switch),N沟道的switch vss(footer switch),两个switch. 但是如果 ...

  3. PAT乙级 1023. 组个最小数 (20)

    1023. 组个最小数 (20) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CAO, Peng 给定数字0-9各若干个.你可以以 ...

  4. 安装 Apache 出现 <OS 10013> 以一种访问权限不允许的方式做了一个访问套接字的尝试

    在安装Apache的过程中出现: 仔细查看提示: make_sock: could not bind to address 0.0.0.0:80 恍然大悟,计算机上安装了IIS7,80端口已占用. 打 ...

  5. 【转】Web UI自动化测试原理

    目前市面上有很多Web UI自动化测试框架,比如WatiN, Selinimu,WebDriver,还有VS2010中的Coded UI等等.  这些框架都可以操作Web中的控件,模拟用户输入,点击等 ...

  6. C#操作CSV存取类

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.D ...

  7. Erlang-基础篇

    一.整数运算: 1.Erlang采用不定长的整数来进行整数的算术演算.在Erlang中,整数运算没有误差,因此无需担心运算溢出,也不用为了一个固定字长容纳不下一个大整数而伤脑筋: 二.变量: 1.所有 ...

  8. java中的单例设计模式

    单例模式有一下特点: 1.单例类只能有一个实例. 2.单例类必须自己自己创建自己的唯一实例. 3.单例类必须给所有其他对象提供这一实例. 单例模式确保某个类只有一个实例,而且自行实例化并向整个系统提供 ...

  9. webApi FileReader

    https://developer.mozilla.org/en-US/docs/Web/API/FileReader https://github.com/node-file-api/FileRea ...

  10. ServiceStack.Redis 之 IRedisTypedClient 04_转

    IRedisTypedClient IRedisTypedClient类相当于IRedicClient的强类型版,其方法与属性大多数与IRedisClient类似. 它支持在Redis中使用Linq查 ...