A. Collecting Coins(水题)

题意:给出三个数a,b,c和另一个数n,保证A+B+C=n并且A+a=B+b=C+c;(A,B,C为n分出来的三个数)如果能够实现,即输出“YES”,否则输出“NO”。

题解:需保证a,b,c,n之和能被3除尽且a,b,c三个数的差之和不能大于n(否则就不能补上),然后判断一下补齐a,b,c后,n的值还能不能被3整除即可。

AC code:

int main()
{
int t;
cin >> t;
while (t--)
{
int a, b, c; int n, maxx;
cin >> a >> b >> c >> n;
maxx = max(a, max(b, c));
int ans = (maxx - a) + (maxx - b) + (maxx - c);
if (((a + b + c + n) % 3 == 0 )&&( ans <=n)&&((n-ans)%3==0))
cout << "YES" << endl;
else
cout << "NO" << endl;
}
return 0;
}

原文地址:https://www.cnblogs.com/Uiney117/p/14128087.html