Codeforces 1294A Collecting Coins

传送门

题意:

给4个整数,\(a,b,c,n\),然后把分成3份分别位A,B,C,(A+B+C=n)
问是否有一种分的方式满足 \(a + A = b + B = c + C\)
满足输出yes,否则输出no

思路:

如果a+b+c+n不是3的倍数,肯定不满足,从题目中可以看出,A,B,C>=0,判断一下即可

代码:

#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <vector>
#include <math.h>
#include <map>
#include <queue>
#include <set>
using namespace std;
typedef long long ll;
const int mod=998244353;
const int MAXN=2e5+50;
const double pi=3.1415926536;
int t;

int main()
{
    //freopen("in.txt","r",stdin);
    scanf("%d",&t);
    while(t--){
        int a,b,c,n;
        scanf("%d%d%d%d",&a,&b,&c,&n);
        int ans=a+b+c+n;
        if(ans%3!=0){
            printf("NO\n");
            continue;
        }
        else
        {
            int p=ans/3;
            if(a<=p&&b<=p&&c<=p)printf("YES\n");
            else printf("NO\n");
        }
    }
    return 0;
}
上一篇:pytorch yolov5


下一篇:Codeforces Round #615 (Div. 3) B Collecting Packages