标签:Collecting Coins Polycarp coins number Cerene test Barbara
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
解题说明:此题是一道模拟题,题意是你有三个姐妹她们分别有 a , b , c枚硬币,你有n枚,你可以把硬币随意分给她们(必须分完),使她们的硬币数A = B = C 可以求出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<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
int main()
{
int t, a, b, c, n, k, i;
scanf("%d", &t);
for (i = 0; i < t; i++)
{
scanf("%d %d %d %d", &a, &b, &c, &n);
k = n + a + c - 2 * b;
if (k % 3 == 0 && k / 3 >= 0 && b - a + k / 3 >= 0 && b - c + k / 3 >= 0)
{
printf("YES\n");
}
else
{
printf("NO\n");
}
}
return 0;
}
标签:Collecting,Coins,Polycarp,coins,number,Cerene,test,Barbara 来源: https://blog.csdn.net/jj12345jj198999/article/details/104091981
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。