New Year Garland

Description
Polycarp is sad — New Year is coming in few days but there is still no snow in his city. To bring himself New Year mood, he decided to decorate his house with some garlands.

The local store introduced a new service this year, called “Build your own garland”. So you can buy some red, green and blue lamps, provide them and the store workers will solder a single garland of them. The resulting garland will have all the lamps you provided put in a line. Moreover, no pair of lamps of the same color will be adjacent to each other in this garland!

For example, if you provide 33 red, 33 green and 33 blue lamps, the resulting garland can look like this: “RGBRBGBGR” (“RGB” being the red, green and blue color, respectively). Note that it’s ok to have lamps of the same color on the ends of the garland.

However, if you provide, say, 11 red, 1010 green and 22 blue lamps then the store workers won’t be able to build any garland of them. Any garland consisting of these lamps will have at least one pair of lamps of the same color adjacent to each other. Note that the store workers should use all the lamps you provided.

So Polycarp has bought some sets of lamps and now he wants to know if the store workers can build a garland from each of them.

Input
The first line contains a single integer tt (1≤t≤1001≤t≤100) — the number of sets of lamps Polycarp has bought.

Each of the next tt lines contains three integers rr, gg and bb (1≤r,g,b≤1091≤r,g,b≤109) — the number of red, green and blue lamps in the set, respectively.
Output
Print tt lines — for each set of lamps print “Yes” if the store workers can build a garland from them and “No” otherwise.
Example

Input
3
3 3 3
1 10 2
2 1 1
Output
Yes
No
Yes
题目大意
给定给定 r 个字符 R,g 个字符 G,b 个字符 B,判断是否存在一种排列方法将其排成一行,不存在两个相同的字符串相邻。
思路
很简单的思维题。我们首先想到的就是不同颜色交替排列,我们可以先找到数量少的两类字符,将之合为一类,与数量最多的字符交替排列。
如r最多,g、b次之,排列便是:r g r b r g r b r…。这样排列最后无非两种情况:r比另外g、b少,或者r比g、b多。
①r比g、b少:那么将r消耗完后,g、b便可以交替排列,最后达成条件,“YES”。
②r比g、b多:r g r b r g r b r… 这样交替排列,当g、b消耗完毕时,此时消耗的r与消耗的g、b总量相等,此时如果剩下的r只剩下一个,那么恰好排在最后符合条件“YES”,但如果还有剩余,那么剩余的r无论排在何处都无法满足条件,只能是“NO”。
总结:如果最多的一种比另外两种之和加1还要多的话,就是NO,否则就是YES。

#include <stdio.h>
int main()
{
    int r,g,b,t;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d%d%d",&r,&g,&b);
        if(r<g)
        {
            int x;
            x=r;r=g;g=x;
        }
        if(r<b)
        {
            int x;
            x=r;r=b;b=x;
        }
        if(r<g+b+2)
            printf("Yes\n");
        else
            printf("No\n");
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值