当前位置: 代码迷 >> 综合 >> CF1395A Boboniu Likes to Color Balls
  详细解决方案

CF1395A Boboniu Likes to Color Balls

热度:43   发布时间:2023-10-14 01:33:56.0

展开
题目描述
Boboniu gives you

rr red balls,
gg green balls,
bb blue balls,
ww 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 TT ( 1\le T\le 1001≤T≤100 ) denoting the number of test cases.

For each of the next TT cases, the first line contains four integers rr , gg , bb and ww ( 0\le r,g,b,w\le 10^90≤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”.

题意翻译
波波牛给了你 rr 个红球,gg 个绿球,bb 个蓝球,ww 个白球。你可以将它们随便排列。

你可以任意多次进行如下操作:

取一个红球,一个绿球,一个蓝球,然后将它们全部变成白球
最后,你需要告诉波波牛你是否能将球的序列变为一个回文序列。

By Dzhao

输入输出样例
输入 #1复制
4
0 1 1 1
8 1 9 3
0 0 0 0
1000000000 1000000000 1000000000 1000000000
输出 #1复制
No
Yes
Yes
Yes
说明/提示
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) to (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.

思路

要使回文就只能有一个奇数或者没有奇数,如果奇数大于1个,那么就看他红蓝绿球可不可以被减,如果不可以(有0),则输出NO,如果可以除了有两个奇数的情况(该情况无论怎么变都是不可能回文的),其他都YES。

代码

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;cin>>t;while(t--){
    int r,g,b,w,cnt=0;cin>>r>>g>>b>>w;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;
// }
// }if(cnt==0){
    cout<<"Yes"<<endl;}else if(cnt==1){
    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;
}
  相关解决方案