zoukankan      html  css  js  c++  java
  • Polygon Triangles

    A polygon is a plane figure that is bounded by a finite amount of straight line segments closing in a loop to form a closed polygonal chain. The segments are called its edges, and the points where two edges meet are the polygon's vertices.

    A triangle is the most basic of all polygons as it has only 3 segments and 3 vertices, anything with less than 3 vertices or segments would be just a line or a point, which are not considered as proper polygons. Triangles have in general many interesting properties, one of them is the called the triangle inequality, which states that the length of any edge of the triangle is strictly less than the sum of the lenghts of the other edges. Formally if we have 3 segments of length ab and c we can construct a triangle if and only if a < b + cb < a + c and c < a + b. This is important, as it gives a necessary and suficient condition to construct a valid, non degenerate triangle from segments, as an example of this, take two segments of length 6 and one of length 10, we can easily make a triangle using these segments because they hold triangle inequality.

    On the other hand if we take segments of lengths 4, 5 and 10 it is not possible to construct a valid triangle.

    Two more important properties about both triangles and polygons is that any polygon can be divided in simple triangles (possibly infinite) and that any set of valid non-degenerate triangles can make together a polygon, this second statement can be shown by induction, the base case is a set consisting of only one valid non-degenerate triangle, which is already a polygon, now for the induction hypothesis, if we have a set of n valid triangles, we could make a polygon with n - 1 of these triangles, then we take the remaining triangle and we just join it to one of the external sides of the polygon we already have and then we get a new valid polygon, all made with valid non-degenerate triangles. The figure shows an example of a possible polygon made by a set of seven triangles.

    Right now the University of Native Artistic Lines (UNAL) is working on an art project where is essential to construct a polygon made of triangles of different colors, that's why they have got many diferent triplets of sticks, where each triplet has a particular different color, now they want to know if it is possible or not to construct a polygon made out of triangles using the procedure described above using all the sticks, but as they have every triplet of a different color, they want to make, if possible, each triangle of a different color, but, it must be just one color for triangle.

    Input

    The first line contains a number n (1 ≤ n ≤ 105) - the number of colored triplets

    Then n lines follow. ith line contains contains each three integers abc (1 ≤ a, b, c ≤ 109) - the length of sticks with the ith color

    Output

    On a single line, print "YES" (without quotes) if it is possible to construct the polygon with all the restrictions, and "NO" (without quotes) otherwise.

    Examples

    Input
    1
    6 6 10
    Output
    YES
    Input
    2
    10 2 2
    2 10 10
    Output
    NO
    Input
    2
    2 2 2
    10 10 10
    Output
    YES
    题目说了些啥,我也没看懂,中午比赛还剩下一丝时间的时候,抱着碰碰运气的态度写了两边之和大于第三边,写完了都很羞愧,感觉这么离奇的想法也是没谁了,居然过了O-O!
     
     1 #include <stdio.h>
     2 
     3 int main()
     4 {
     5     int n, i, flag, a, b, c;
     6     scanf("%d", &n);
     7     flag = 1;
     8     for(i=0;i<n;i++)
     9     {
    10         scanf("%d %d %d", &a, &b, &c);
    11         if(a+b<=c||a+c<=b||b+c<=a) flag=0;
    12     }
    13     if(flag==1) printf("YES
    ");
    14     else printf("NO
    ");
    15     return 0;
    16 }
     
     
     
  • 相关阅读:
    135. Candy(Array; Greedy)
    69. Sqrt(x) (Divide-and-Conquer)
    109. Convert Sorted List to Binary Search Tree (List; Divide-and-Conquer, dfs)
    108.Convert Sorted Array to Binary Search Tree(Array; Divide-and-Conquer, dfs)
    34. Search for a Range (Array; Divide-and-Conquer)
    35. Search Insert Position (Array; Divide-and-Conquer)
    82. Remove Duplicates from Sorted List II (List)
    python dict list tuple
    python unix时间戳
    字符串哈希函数
  • 原文地址:https://www.cnblogs.com/0xiaoyu/p/11345639.html
Copyright © 2011-2022 走看看