CF1395A Boboniu Likes to Color Balls

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;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值