CF1395A Boboniu Likes to Color Balls
题目描述
Boboniu gives you r red balls, g green balls, b blue balls, 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.
输入格式
The first line contains one integer 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 , b and w ( 0≤r,g,b,w≤10^9 ).
输出格式
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”.
思路
- 对于所有给出的四种球,有大于三种是偶数时,一定能摆成回文,当红、蓝、绿中有一种与另两种奇偶不同时,一定不能摆成回文,可以分为0和大于零的情况,当偶数个数大于等于2时,一定不能摆成回文(红蓝绿至少有一个不是偶数)。
代码实现
#include <bits/stdc++.h>
using namespace std;
int main(){
int t;
cin>>t;
while(t--){
long long int r,g,b,w;
cin>>r>>g>>b>>w;
int cnt=0;//记录偶数个数
if(r%2==0) cnt++;
if(g%2==0) cnt++;
if(b%2==0) cnt++;
if(w%2==0) cnt++;
if(cnt>=3) cout<<"Yes"<<endl;
else{
if(r==0||g==0||b==0){
cout<<"No"<<endl;
}else{
if(cnt==2) cout<<"No"<<endl;
else cout<<"Yes"<<endl;
}
}
}
return 0;
}