题解 | 元素方碑

元素方碑

https://www.nowcoder.com/practice/5c6e7ed4726e41f4ac99a4dedf1e5bb2

#include <stdio.h>
#include <stdlib.h>
typedef long long ll;

int main(void) {
    int t;
    scanf("%d", &t);

    while (t--) {
        int n;
        scanf("%d", &n);
        ll* a = (ll*)malloc(n * sizeof(ll));
        ll sum = 0;
        for (int i = 0; i < n; i++) {
            scanf("%lld", &a[i]);
            sum += a[i];
        }
        if (sum % n != 0) {
            printf("NO\n");
            free(a);
            continue;
        }
        ll average = sum / n;
        ll odd_sum = 0;
        for (int i = 0; i < n; i += 2)
            odd_sum += a[i] - average;

        if (odd_sum == 0)
            printf("YES\n");
        else
            printf("NO\n");

        free(a);
    }
    return 0;
}

全部评论

相关推荐

爱刷美剧的菠萝蜜巴比...:丢给gpt,让他优化实习 切合实际 突出产出 可以不局限简历内容,,然后就背就好了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务