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 ...
随机推荐
- bzoj千题计划272:bzoj4557: [JLoi2016]侦察守卫
http://www.lydsy.com/JudgeOnline/problem.php?id=4557 假设当前到了x的子树,现在是合并 x的第k个子树 f[x][j] 表示x的前k-1个子树该覆盖 ...
- 洛谷 P3994 高速公路
https://www.luogu.org/problemnew/show/P3994 设dp[i] 表示第i个城市到根节点的最小花费 dp[i]=min{ (dis[i]-dis[j])*P[i]+ ...
- Automate Tdxw
Automate trade module in Tdxw Code # coding: utf-8 """ Created on Thu Dec 07 10:57:45 ...
- 广度优先搜索(BFS)----------------(TjuOj1140_Dungeon Master)
这次整理了一下广度优先搜索的框架,以后可以拿来直接用了.TjuOj1140是一个三维的迷宫题,在BFS时我增加了一个控制数组,用来对队列的出队进行控制,确保每次出队的结点均为同一步长的结点,个人认为比 ...
- [转]CMake cache
CMakeCache.txt 可以将其想象成一个配置文件(在Unix环境下,我们可以认为它等价于传递给configure的参数). CMakeLists.txt 中通过 set(... CACHE . ...
- CentOS 无法通过 yum 安装新版 nodejs 解决办法(安装的还是老版的)
官网安装说明:CentOS 安装 nodejs 第一步: curl --silent --location https://rpm.nodesource.com/setup_10.x | sudo b ...
- MySQL 5.6 Replication 复制 FAQ
原文请参照MySQL官方文档Reference Manual,版本5.6.10. 复制功能使得数据可以从一个MySQL数据库(master主库)复制到另一个或多个MySQL数据库(slave从库).缺 ...
- Linux中断(interrupt)子系统之一:中断系统基本原理【转】
转自:http://blog.csdn.net/droidphone/article/details/7445825 这个中断系列文章主要针对移动设备中的Linux进行讨论,文中的例子基本都是基于AR ...
- [cookie篇]cookie-parser之parser.js
cookie-parser的作用,官方的说法是:Parse Cookie header and populate req.cookies with an object keyed by the coo ...
- 乐视max2 在开发中无法打印某些logcat 解决方案
乐视屏蔽了打印log.d等类型logcat.解决方案:拨号键盘 *#*#76937#*#* 出现页面后选最下面那个选项就有了.