Codeforces #664 (Div. 2) A. Boboniu Likes to Color Balls (思维)

A. Boboniu Likes to Color Balls(思维)

time limit per test:1 second
memory limit per test:256 megabytes
input:standard input
output:standard output

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(1T100) 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) (0r,g,b,w109).

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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值