Codeforces 1294A Collecting Coins

题目链接:

Codeforces 1294A Collecting Coins

思路:

首先将三个人的硬币数量都变为max(a,b,c)max(a,b,c),且剩下的硬币应为3的倍数

代码:

#include<bits/stdc++.h>

using namespace std;

int main() {
#ifdef MyTest
	freopen("Sakura.txt", "r", stdin);
#endif	
	ios::sync_with_stdio(false);
	cin.tie(0);
	int t;
	cin >> t;
	while(t--) {
		int a[3], n;
		for(int i = 0; i < 3; i++) cin >> a[i];
		cin >> n;
		sort(a, a + 3);
		int ans = a[2] * 2 - a[0] - a[1];
		if(n >= ans && (n - ans) % 3 == 0) puts("YES");
		else puts("NO");	
	}
	return 0;
}
原文地址:https://www.cnblogs.com/yuhan-blog/p/12308650.html