A16128 | Array Coloring
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
You are given an array consisting of $n$ integers. Your task is to determine whether it is possible to color all its elements in two colors in such a way that the sums of the elements of both colors have the same parity and each color has at least one element colored.
For example, if the array is \[ $1,2,4,3,2,3,5,4$ \], we can color it as follows: \[ $\color{blue}{1},\color{blue}{2},\color{red}{4},\color{blue}{3},\color{red}{2},\color{red}{3},\color{red}{5},\color{red}{4}$ \], where the sum of the blue elements is $6$ and the sum of the red elements is $18$ .
For example, if the array is \[ $1,2,4,3,2,3,5,4$ \], we can color it as follows: \[ $\color{blue}{1},\color{blue}{2},\color{red}{4},\color{blue}{3},\color{red}{2},\color{red}{3},\color{red}{5},\color{red}{4}$ \], where the sum of the blue elements is $6$ and the sum of the red elements is $18$ .
输入格式
The first line contains an integer $t$ ( $1 \le t \le 1000$ ) — the number of test cases.
Each test case begins with a line containing an integer $n$ ( $2 \le n \le 50$ ) — the length of the array $a$ .
The next line contains $n$ integers $a_1,a_2, \dots, a_n$ ( $1 \le a_i \le 50$ ) — the elements of the array $a$ .
Each test case begins with a line containing an integer $n$ ( $2 \le n \le 50$ ) — the length of the array $a$ .
The next line contains $n$ integers $a_1,a_2, \dots, a_n$ ( $1 \le a_i \le 50$ ) — the elements of the array $a$ .
输出格式
For each test case, output "YES" (without quotes) if it is possible to color the array in two colors in such a way that the sums of the elements of both colors have the same parity and each color has at least one element colored, and "NO" otherwise.
You can output "Yes" and "No" in any case (for example, the strings "yES", "yes", and "Yes" will be recognized as correct answers).
You can output "Yes" and "No" in any case (for example, the strings "yES", "yes", and "Yes" will be recognized as correct answers).
输入输出样例
输入 #1
7 8 1 2 4 3 2 3 5 4 2 4 7 3 3 9 8 2 1 7 5 5 4 3 2 1 4 4 3 4 5 2 50 48
输出 #1
YES NO YES YES NO YES YES
The first sample is described in the statement.
In the second sample, there are only two colorings $[\color{blue}{4},\color{red}{7}]$ and $[\color{red}{4},\color{blue}{7}]$ , but in both cases the parity of sums is different.
In the third sample, you can color $[\color{blue}{3},\color{blue}{9},\color{red}{8}]$ and $12$ and $8$ are both even.
In the second sample, there are only two colorings $[\color{blue}{4},\color{red}{7}]$ and $[\color{red}{4},\color{blue}{7}]$ , but in both cases the parity of sums is different.
In the third sample, you can color $[\color{blue}{3},\color{blue}{9},\color{red}{8}]$ and $12$ and $8$ are both even.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted