CF1279 A. New Year Garland

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 3 red, 3 green and 3 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, 1 red, 10 green and 2 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 𝑡 (1≤𝑡≤100) — the number of sets of lamps Polycarp has bought.

Each of the next 𝑡 lines contains three integers 𝑟, 𝑔 and 𝑏 (1≤𝑟,𝑔,𝑏≤109) — the number of red, green and blue lamps in the set, respectively.

Output
Print 𝑡 lines — for each set of lamps print “Yes” if the store workers can build a garland from them and “No” otherwise.

Example
inputCopy
3
3 3 3
1 10 2
2 1 1
outputCopy
Yes
No
Yes
Note
The first two sets are desribed in the statement.

The third set produces garland “RBRG”, for example.

题意:
给出A,B,C的数目,求是否存在排列方式使得没有相邻两个相同。
思路:
我写的时候思路没到位,想的是先放三个的再放两个的,这是假算法。
贪心的算,肯定要先把最大的那个用完,假设是A ≤ B ≤ C。
C最大可以等于A + B + 1,如果C > A + B + 1,那肯定是放不下的(CACBCXCXC…)
如果C ≤ A + B + 1. 取完C后一定可以使得A = B或者A + 1 = B,那么剩下的就直接放就好了。

#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>

using namespace std;

int a[10];
int main()
{
    int T;scanf("%d",&T);
    while(T--)
    {
        scanf("%d%d%d",&a[1],&a[2],&a[3]);
        sort(a + 1,a + 1 + 3);
        if(a[1] + a[2] + 1 >= a[3])
        {
            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、付费专栏及课程。

余额充值