zoukankan      html  css  js  c++  java
  • CF codeforces A. New Year Garland【Educational Codeforces Round 79 (Rated for Div. 2)】

    A. New Year Garland

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

    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 (1t1001≤t≤100) — the number of sets of lamps Polycarp has bought.

    Each of the next tt lines contains three integers rr, gg and bb (1r,g,b1091≤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
    Copy
    3
    3 3 3
    1 10 2
    2 1 1
    
    Output
    Copy
    Yes
    No
    Yes
    
    Note

    The first two sets are desribed in the statement.

    The third set produces garland "RBRG", for example.

     

    既然首尾颜色可以相同,那怎么能叫花环呢

    那应该就是一个链啊

    RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR

    BBBBBBBBBBBBBBBBBBBBBBBBBB

    GGGGGGGGGGGGGGGGGGGGG

    RBRBRBRBRBRBRBRBRBRBRBRBRBRBRBRBRRRRRRRRRRRRR;

    RBRBRBRBRBRBRBRBRBRBRBRBRBRBRBRBRGRGRGRGRGRG

    ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑

    简明扼要的表达了思路

    【这题是大佬直接讲的他的思路】(白嫖思路)

    思路如下

    首先先排序,先把最大的和第二大的插空(RBRBRBRBRBRBRBRRRRRRRRR)

    这时候肯定多了一些最大的那个颜色,这时候就把最少的颜色拿来补

    我们只要知道最少的颜色满足的某个区间,就可以快乐输出了、

    a[0]>=abs(a[1]-a[2])-1且a[0]<=a[1]+a[2]+abs(a[1]-a[2])“a[0]表示最小的数”

    不过a[0]>***的式子很多余。。。。。(不管了,我好不容易推出来的式子我就要加上)

     1 #include <bits/stdc++.h>
     2 
     3 using namespace std;
     4 
     5 int main()
     6 {
     7     long long  a[3];
     8     int t;
     9     cin>>t;
    10     while(t--){
    11         cin>>a[0]>>a[1]>>a[2];
    12         sort(a,a+3);
    13         if(a[0]>=abs(a[1]-a[2])-1&&a[0]<=a[1]+a[2]+abs(a[1]-a[2]))
    14     cout<<"yes"<<' '; 15 else cout<<"no"<<' '; 16 } 16 return 0; 17 }
  • 相关阅读:
    [LeetCode] 94. Binary Tree Inorder Traversal 二叉树的中序遍历
    [LeetCode] 103. Binary Tree Zigzag Level Order Traversal 二叉树的之字形层序遍历
    Notepad++ Shortcuts 快捷键
    IplImage 与 QImage 相互转换
    [LeetCode] 105. Construct Binary Tree from Preorder and Inorder Traversal 由先序和中序遍历建立二叉树
    QMessageBox 使用方法
    Qt5 和 Qt4 的一些改动和不同
    Qt5.4 VS2010 Additional Dependancies
    [LeetCode] Construct Binary Tree from Inorder and Postorder Traversal 由中序和后序遍历建立二叉树
    [LeetCode] Best Time to Buy and Sell Stock IV 买卖股票的最佳时间之四
  • 原文地址:https://www.cnblogs.com/ahijing/p/12546269.html
Copyright © 2011-2022 走看看