Codeforces Round #615 (Div. 3)A. Collecting Coins
A. Collecting Coins
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Polycarp has three sisters: Alice, Barbara, and Cerene. They're collecting coins. Currently, Alice has aa coins, Barbara has bb coins and Cerene has cc coins. Recently Polycarp has returned from the trip around the world and brought nn coins.
He wants to distribute all these nn coins between his sisters in such a way that the number of coins Alice has is equal to the number of coins Barbara has and is equal to the number of coins Cerene has. In other words, if Polycarp gives AA coins to Alice, BB coins to Barbara and CC coins to Cerene (A+B+C=nA+B+C=n), then a+A=b+B=c+Ca+A=b+B=c+C.
Note that A, B or C (the number of coins Polycarp gives to Alice, Barbara and Cerene correspondingly) can be 0.
Your task is to find out if it is possible to distribute all nn coins between sisters in a way described above.
You have to answer tt independent test cases.
Input
The first line of the input contains one integer tt (1≤t≤1041≤t≤104) — the number of test cases.
The next tt lines describe test cases. Each test case is given on a new line and consists of four space-separated integers a,b,ca,b,c and nn (1≤a,b,c,n≤1081≤a,b,c,n≤108) — the number of coins Alice has, the number of coins Barbara has, the number of coins Cerene has and the number of coins Polycarp has.
Output
For each test case, print "YES" if Polycarp can distribute all nn coins between his sisters and "NO" otherwise.
Example
input
Copy
5
5 3 2 8
100 101 102 105
3 2 1 100000000
10 20 15 14
101 101 101 3
output
Copy
YES
YES
NO
NO
YES
题目链接:https://codeforces.com/contest/1294/problem/A
题意:
你有三个姐妹她们分别有 a , b , c枚硬币,你有n枚,你可以把硬币随意分给她们(必须分完),使她们的硬币数A = B = C
第一题一般是简单的数学推导:
设分别分给三个姐妹x,y,z
有a+x=b+y=c+z,即a+x+b+y+c+z=3*(a+x)=3*(b+y)=3*(c+z)=a+b+c+n
可以求出x=(a+b+c+n-3*a)/3,y=x=(a+b+c+n-3*b)/3,z=(a+b+c+n-3*c)/3,如果三个式子的分母只要有一个小于零或者不能被3整除就不能分完,否则可以
#include<bits/stdc++.h>
#define ll long long
#define rg register ll
using namespace std;
ll n,t,a,b,c;
int main()
{
cin>>t;
while(t--)
{
cin>>a>>b>>c>>n;
ll k1=(a+b+c+n-3*a)/3,k2=(a+b+c+n-3*b)/3,k3=(a+b+c+n-3*c)/3;
ll flag=0;
//cout<<k1<<" "<<k2<<" "<<k3<<endl;
if(a+b+c+n-3*a<0)flag=1;
if(a+b+c+n-3*b<0)flag=1;
if(a+b+c+n-3*c<0)flag=1;
if(k1*3!=a+b+c+n-3*a)flag=1;
if(k2*3!=a+b+c+n-3*b)flag=1;
if(k3*3!=a+b+c+n-3*c)flag=1;
!flag?cout<<"YES"<<endl:cout<<"NO"<<endl;
}
while(1)getchar();
return 0;
}
- Linux shell 程序设计1——安装及入门
- 偶遇--《坑新人--前端专用面试题》
- 简单的说下,(function(){...})() 与 (function(){...}()) 有什么区别?
- ASP.NET Process Model之二:ASP.NET Http Runtime Pipeline[上篇]
- Shell常用命令小结
- 插入法排序
- ASP.NET Process Model之二:ASP.NET Http Runtime Pipeline - Part II
- 震惊了!这样的js面试题让所有人-男默女泪
- 前端知识学了却不会用,都是没走心
- var a="xx";a=a+"ss";a的值变了,但"xx"字符串并没有变
- 先行者计划--1109微课总结 | 《通过二个demo初识webPack》
- 先行者计划--1107微课 《什么是Vuex?》| 文字简版
- 脱离前端菜鸟层次的二个关键点
- 【课堂笔记】先行者 3.0版本的vueJs课程的第三次课
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- python Unhandled exception in event loop:错误解决
- SAP Fiori image的显示原理
- 解决Error:All flavors must now belong to a named flavor dimension.
- 同时搞定Android和iOS的Dart语言(3):数值类型
- SAP Fiori图标(icon)设计原理
- SAP Fiori应用发生超时错误的一个可能原因
- 如何用云开发快速搭建实时 Todo List 应用
- Angular应用的入口
- Angular里的structural directive的一个例子
- Angular条件指令ngIf的一个例子
- Angular的property binding一个例子
- Angular里的按钮事件注册方法一例
- 如何使用Angular的@Input()装饰器
- Angular父子Component之间的事件通知机制
- dotnet OpenXML 解析 PPT 文本字体获取详解