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;
}
}
Codeforces Round #258 (Div. 2) C. Predict Outcome of the Game 水题的更多相关文章
- 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三队赢的场次的关系 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 【打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 ...
随机推荐
- 转自知乎大神---什么是 JS 原型链?
我们知道 JS 有对象,比如 var obj = { name: 'obj' } 我们可以对 obj 进行一些操作,包括 「读」属性 「新增」属性 「更新」属性 「删除」属性 下面我们主要来看一下「读 ...
- 20155203 2016-2017-2 《Java程序设计》第7周学习总结
20155203 2016-2017-2 <Java程序设计>第6周学习总结 教材学习内容总结 1.Lambda表达式.(使用interface函数接口) 2.Lambda的方法参考Met ...
- HDU 3371 Connect the Cities 最小生成树(和关于sort和qsort的一些小发现)
解题报告:有n个点,然后有m条可以添加的边,然后有一个k输入,表示一开始已经有k个集合的点,每个集合的点表示现在已经是连通的了. 还是用并查集加克鲁斯卡尔.只是在输入已经连通的集合的时候,通过并查集将 ...
- vue路由DEMO
index.js,index.vue,course.vue,master.vue等 import Vue from 'vue' import Router from 'vue-router' impo ...
- eclipse中可以导入其它工具编写的RobotFramework脚本吗?
在Robotframework的官方网站中,提供了非常多的编辑RF的工具.比如Ride,eclipse,sublime,notepad++等. 网上查到的资料,大部分都是Ride这个编辑工具的使用.在 ...
- kibana提示"[illegal_argument_exception] mapper [hits] cannot be changed from type [long] to [integer]"
=============================================== 2019/1/30_第1次修改 ccb_warlock == ...
- 配置Eclipse编写HTML/JS/CSS/JSP页面的自动提示
我们平时用eclipse开发jsp页面时智能提示效果不太理想,今天用了两个小时发现了eclipse也可以像Visual Studio 2008那样完全智能提示HTML/JS/CSS代码,使用eclip ...
- tensorflow variable的保存和修改(加载一部分variable到新的model中)
link: https://www.tensorflow.org/guide/saved_model 中文博客:https://blog.csdn.net/Searching_Bird/article ...
- Tomcat8 启动中提示 org.apache.catalina.webresources.Cache.getResource Unable to add the resource
Tomcat8 启动过程中提示: org.apache.catalina.webresources.Cache.getResource Unable to add the resource at xx ...
- Linux系统运维笔记(四),CentOS 6.4安装 MongoDB
Linux系统运维笔记(四),CentOS 6.4安装 MongoDB 1,下载 https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.0.6 ...