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;
}
}

Codeforces Round #258 (Div. 2) C. Predict Outcome of the Game 水题的更多相关文章

  1. 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三队赢的场次的关系 ...

  2. Codeforces Round #356 (Div. 2)B. Bear and Finding Criminals(水题)

    B. Bear and Finding Criminals time limit per test 2 seconds memory limit per test 256 megabytes inpu ...

  3. Codeforces Round #343 (Div. 2) A. Far Relative’s Birthday Cake 水题

    A. Far Relative's Birthday Cake 题目连接: http://www.codeforces.com/contest/629/problem/A Description Do ...

  4. Codeforces Round #385 (Div. 2) A. Hongcow Learns the Cyclic Shift 水题

    A. Hongcow Learns the Cyclic Shift 题目连接: http://codeforces.com/contest/745/problem/A Description Hon ...

  5. Codeforces Round #396 (Div. 2) A. Mahmoud and Longest Uncommon Subsequence 水题

    A. Mahmoud and Longest Uncommon Subsequence 题目连接: http://codeforces.com/contest/766/problem/A Descri ...

  6. Codeforces Round #375 (Div. 2) A. The New Year: Meeting Friends 水题

    A. The New Year: Meeting Friends 题目连接: http://codeforces.com/contest/723/problem/A Description There ...

  7. Codeforces Round #359 (Div. 2) B. Little Robber Girl's Zoo 水题

    B. Little Robber Girl's Zoo 题目连接: http://www.codeforces.com/contest/686/problem/B Description Little ...

  8. Codeforces Round #358 (Div. 2) B. Alyona and Mex 水题

    B. Alyona and Mex 题目连接: http://www.codeforces.com/contest/682/problem/B Description Someone gave Aly ...

  9. 【打CF,学算法——二星级】Codeforces Round #313 (Div. 2) B. Gerald is into Art(水题)

    [CF简单介绍] 提交链接:http://codeforces.com/contest/560/problem/B 题面: B. Gerald is into Art time limit per t ...

随机推荐

  1. Linux iptables常用命令的使用

    为什么会有本文 因为最近帮一个朋友布署一个上网梯子,他那边本来用的是v2ray,但是他想用ssr,但是安装配置ssr过程中出了很多问题,比如linux内核版本4.9有点老,不支持bbr加速.无法连接s ...

  2. 关于MYSQL group by 分组按时间取最大值的实现方法

    类如 有一个帖子的回复表,posts( id , tid , subject , message ,  dateline ) , id 为 自动增长字段, tid为该回复的主题帖子的id(外键关联), ...

  3. [机器学习&数据挖掘]机器学习实战决策树plotTree函数完全解析

    在看机器学习实战时候,到第三章的对决策树画图的时候,有一段递归函数怎么都看不懂,因为以后想选这个方向为自己的职业导向,抱着精看的态度,对这本树进行地毯式扫描,所以就没跳过,一直卡了一天多,才差不多搞懂 ...

  4. Linux中断(interrupt)子系统之一:中断系统基本原理【转】

    转自:http://blog.csdn.net/droidphone/article/details/7445825 这个中断系列文章主要针对移动设备中的Linux进行讨论,文中的例子基本都是基于AR ...

  5. css-position属性实例2

    position 1) fixed 固定在页面某个位置 2) absolute 也可以固定在某个位置,一般结合relative使用 注: 1)fixed和absoulue区别,假如一个div固定在右下 ...

  6. Java基础85 MVC开发模式

    1.MVC开发模式 本文用 Servlet+JSP+javaBean 的开发模式来讲解 Model:用javabean实现,用于封装业务数据View:用jsp实现,用于显示数据Controller:用 ...

  7. laravel 打印sql语句

    public function getCurrencyOrder($user_id=70,$pid=252,$register=['register:first']) { DB::connection ...

  8. SqlServer中Sql查看存储过程

    ( 一)利用Sql语句查询数据库中的所有表 1.利用sysobjects系统表 select * from sysobjects where xtype='U'  2,利用sys.tables目录视图 ...

  9. Linux系统运维笔记(四),CentOS 6.4安装 MongoDB

    Linux系统运维笔记(四),CentOS 6.4安装 MongoDB 1,下载 https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.0.6 ...

  10. application/json 四种常见的 POST 提交数据方式

    四种常见的 POST 提交数据方式   HTTP/1.1 协议规定的 HTTP 请求方法有 OPTIONS.GET.HEAD.POST.PUT.DELETE.TRACE.CONNECT 这几种.其中 ...