https://codeforces.com/contest/1472/problem/B
題意:給你一堆由面值為1或2的硬幣,問你能不能把這堆硬幣分成兩堆,使得兩堆硬幣面值和相同,
可以發現如果硬幣和如果是奇數,無法平均分配(硬幣無法鋸開~),然后在和為偶數的前提下,如果面值為2的硬幣數量為奇數,面值為1的硬幣數量為0,那也是無法平均分配的,剩下的情況下就是2的數量為偶數(包括0),1的數量為偶數辣,肯定能平均分,
(如果2的數量是偶數1的數量是奇數就無法滿足和為偶數了~)
#include <bits/stdc++.h>
using namespace std;
#define qc std::ios::sync_with_stdio(0);
int a[101];
int main() {
qc;
cin.tie(0);
int t ;
cin >> t;
while (t--) {
int n;
int ans = 0;
int c1 = 0;
int c2 = 0;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
if (a[i] == 2)
c2++;
if (a[i] == 1)
c1++;
ans += a[i];
}
if (ans % 2 != 0) {
cout << "NO" << endl;
continue;
}
if (c2 % 2 != 0) {
if (c1 == 0) {
cout << "NO" << endl;
continue;
}
}
cout << "YES" << endl;
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/245699.html
標籤:其他
