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");elseprintf("No\n");}
}

New Year Garland相关推荐

  1. K-periodic Garland CodeForces - 1353E(贪心)

    You are given a garland consisting of n lamps. States of the lamps are represented by the string s o ...

  2. K-periodic Garland CodeForces - 1353E(暴力+贪心+dp)

    题意: 给定长为 n 的 0, 1 字符串,你可以通过一次操作改变一个字符(0 变 1 or 1 变 0),问最少几次操作可以使任意相邻两个 1 之间的距离为 k ? 题目: You are give ...

  3. 1108D. Diverse Garland

    D. Diverse Garland:题目 什么脑瘫题目!!!可恶,和dp有什么关系?但是强迫症让我不得不写,空一个很难受!! #include <bits/stdc++.h> using ...

  4. Codeforces 1287C Garland

    题目链接: Codeforces 1287C Garland 思路: 我们记dp[i][j][0]和dp[i][j][1]分别为第i个为奇数/偶数且前i个里面有j个偶数的情况下,第i个的最小复杂度: ...

  5. 题解 UVA1555 【Garland】(二分)

    题面 最近有人问我这个题这么做,光讲几句貌似没什么用,干脆发个题解吧(话说什么有人会来问我这个蒟蒻) 题面的意思大概就是说每个点的高度都和旁边2个点有关,整张图没有高度小于0的点,求最后一个点B的最低 ...

  6. codeforces 767C - Garland

    题目链接:http://codeforces.com/contest/767/problem/C 问能否将一棵带点权的书分成点权$3$块,求任意方案. 其实考虑一棵以$x$为根的子树权值为${\fra ...

  7. CF767C Garland

    一道树形DP \(Translate\) 有一颗\(n\)个节点的树 第\(i\)个节点权值为\(a_i\) \((n<=10^6,-100<=a_i<=100)\) 问是否能够删除 ...

  8. CodeForces - 1353E K-periodic Garland(思维+dp)

    题目链接:点击查看 题目大意:给出 n 个灯泡以及其初始状态(开或关),每次操作可以将任意一个灯泡的状态置反,问最少需要操作多少次,可以使得所有开着的灯泡之间相距 k 个单位 题目分析:因为需要满足所 ...

  9. CodeForces - 1287C Garland(贪心)

    题目链接:点击查看 题目大意:原本有一个1~n的排列,现在缺少了一些数字,用0来代替,现在要求将缺少的数字重新填回去,要求代价和最少,规定代价为:若相邻两个数字的奇偶性不同,则代价为1,否则代价为0 ...

  10. E:K-periodic Garland(DP)

    思路 每个点我们有两种决策,其值为0或1: 如果点我们放置0的话,我们有其前一位数字是零,或者其前一位数字是一. 如果这个点我们放置1的话,我们有其前面是按照每k个数字都出现一次1的排列,也有可能其前 ...

最新文章

  1. 如何使用 OpenCV Python 检测颜色
  2. ffmpeg 0.8.11 VC编译的SDK已经发布
  3. 使用SDWebImage淡入淡出的方式加载图片
  4. php 整数 比较,php中字符串和整数比较
  5. 制打印如下所示的n行数字金字塔_一日一技:在Python中实现阿拉伯数字加上中文数字...
  6. laravel 配置微信公众号时{errcode:-106,errmsg:token check fail}
  7. python使用spark-sql读取数据并可视化_使用Spark SQL读取HBase上的数据
  8. 深入学习二叉树(三) 霍夫曼树
  9. android+proguard目录,Android proguard问题:路径可能不是null或空字符串.路径=“空”...
  10. vs 下如何调试js
  11. poj 1328 贪心+qsort
  12. malloc 是如何分配内存的?
  13. 关于SCN引起DBLINK的问题解决方法说明--打补丁
  14. java 微信 图灵机器人_SAE服务下用java实现微信公众账号图灵机器人
  15. 《Miss Talk》第07期:对话拓课云联合创始人兼CTO 王晓伟
  16. 为什么大学老师只教c语言,开挂的相声演员:做大学老师,主讲计算机C语言,课堂爆笑不断!...
  17. 感觉本人对事待人处理不当。
  18. 原奶周期与伊利、蒙牛的兼并战争
  19. 光伏并网逆变器设计方案,附有相关的matlab电路仿真文件,以及DSP的程序代码
  20. 全部资源,都在这里了

热门文章

  1. NUC980 PWM
  2. 《局域网技术与组网工程实验》学习笔记
  3. QuickTime文件格式
  4. c语言中专业英文词汇的意思,C语言常见英文词汇表
  5. AEAI Portal中集成百度地图
  6. MySQL第41题怎么评分_MySQL试题-测试、复习、查看
  7. 编译原理 C-Minus 语法分析(Flex / Bison)
  8. SpringBoot整合Tomcat中的组件
  9. 计算机网络连接限制,网络受限制或无连接怎么办?电脑网络连接受限制或无连接问题...
  10. 多御浏览器安卓版有哪些地方值得下载使用?