A. Boboniu Likes to Color Balls(思维)
Boboniu gives you
- r r r red balls,
- g g g green balls,
- b b b blue balls,
- w w w white balls.
He allows you to do the following operation as many times as you want:
- Pick a red ball, a green ball, and a blue ball and then change their color to white.
You should answer if it’s possible to arrange all the balls into a palindrome after several (possibly zero) number of described operations.
Input
The first line contains one integer
T
(
1
≤
T
≤
100
)
T (1≤T≤100)
T(1≤T≤100) denoting the number of test cases.
For each of the next T cases, the first line contains four integers r , g r, g r,g, b b b and w w w ( 0 ≤ r , g , b , w ≤ 109 ) (0≤r,g,b,w≤109) (0≤r,g,b,w≤109).
Output
For each test case, print “Yes” if it’s possible to arrange all the balls into a palindrome after doing several (possibly zero) number of described operations. Otherwise, print “No”.
Example
input
4
0 1 1 1
8 1 9 3
0 0 0 0
1000000000 1000000000 1000000000 1000000000
output
No
Yes
Yes
Yes
Note
In the first test case, you’re not able to do any operation and you can never arrange three balls of distinct colors into a palindrome.
In the second test case, after doing one operation, changing ( 8 , 1 , 9 , 3 ) (8,1,9,3) (8,1,9,3) to ( 7 , 0 , 8 , 6 ) (7,0,8,6) (7,0,8,6), one of those possible palindromes may be “rrrwwwbbbbrbbbbwwwrrr”.
A palindrome is a word, phrase, or sequence that reads the same backwards as forwards. For example, “rggbwbggr”, “b”, “gg” are palindromes while “rgbb”, “gbbgr” are not. Notice that an empty word, phrase, or sequence is palindrome.
题意:给定4个颜色的小球的个数,其中可以通过用1个红球+1个绿球+1个篮球组合在一起换3个白球,并且可以无数次换。如果能够满足这些颜色球存在可以排成回文,则输出“Yes”,否则输出“No”。
题解:核心思想:无论怎么变换,最终的结果要求满足,四种颜色的球,其中有三种颜色的球的个数为偶数,剩下最后一个颜色的球则奇偶均可。(详情,请看代码)
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
int a[5];//储存不同颜色球的数量
int main()
{
IOS;
int t;
cin >> t;
while (t--)
{
int x = 0;
for (int i = 0; i < 4; i++)
{
cin >> a[i];//输入不同颜色球的数量
if (a[i] % 2 == 0)//如果为偶数,做标记
x++;
}
if (x >= 3) //如果有3个不同颜色球的数量为偶数,则无论剩下的一个为奇数还是偶数都是成立的。
{
printf("Yes\n");
continue;
}
int flag = 0;
for (int i = 0; i < 3; i++)
{
if (a[i] == 0) //如果三种颜色的球,有一种为0,flag=1;
{
flag = 1;
break;
}
}
if (flag) //如果三种颜色的球,有一种为0,则为No
printf("No\n");
else
{
int cnt = 0;
for (int i = 0; i < 3; i++)
{
if (a[i] % 2)
cnt++; //三种颜色中,奇数的数量
}
if (cnt == 3)//三个奇数+白球(无论奇偶都可以)
printf("Yes\n");
else
{
if (cnt == 2 && a[3] % 2 == 1)//两个为奇数,白球为奇数也可以
printf("Yes\n");
else
printf("No\n");
}
}
}
return 0;
}