CF 6A Triangle (determine if a triangle can be formed)

Source: Internet
Author: User
Tags integer numbers


Triangletime limit:2000msmemory limit:65536kbthis problem'll be judged onCodeforces. Original id:6a
64-bit integer IO format:%i64dJava class Name:(Any)Prev Submit Status Statistics discuss Next

Johnny has a younger sister Anne, who is very clever and smart. As she came home from the kindergarten, she told he brother about the task that she kindergartener asked her to solve. The task was just to construct a triangle out of four sticks of different colours. Naturally, one of the sticks is extra. It is not a allowed to break the sticks or use their partial length. Anne has perfectly solved this task, now she's asking Johnny to do the same.

The boy answered this he would cope with it without any difficulty. However, after a and he found out that different tricky things can occur. It can happen that it's impossible to construct a triangle of a positive area, but it's possible to construct a Degenera Te Triangle. It can be, and that's it's impossible to construct a degenerate triangle even. As Johnny is very-lazy, he does not want to consider such a big amount of cases, he asks the help him.

Input

The first line of the "input contains four space-separated positive" integer numbers not exceeding 100-lengthes of the STI Cks.

Output

Output TRIANGLE If it is possible to construct a non-degenerate TRIANGLE. Output SEGMENT If the first case cannot take place and it was possible to construct a degenerate triangle. Output Impossible if it is impossible to construct any triangle. Remember that is to use three sticks. It is not a allowed to break the sticks or use their partial length.

Sample Inputinput
4 2 1 3
Output
TRIANGLE
Input
7 2 2 4
Output
SEGMENT
Input
3 5 9 1
Output
Impossible
Sourcecodeforces Beta Round #6 (Div. 2 only)Test Instructions: for 4 line segments, ask if they can form triangles, line segments, or do not form triangles.

Q God deserves to be the Q God, referring to his code.


AC Code:

#include <iostream> #include <algorithm> #include <cstdio>using namespace Std;int main () {    int a[4 ];    for (int i=0;i<4;i++)        cin>>a[i];    Sort (a,a+4);    for (int i=0;i<2;i++)        if (a[i]+a[i+1]>a[i+2])            return 0*printf ("TRIANGLE");    for (int i=0;i<2;i++)        if (a[i]+a[i+1]==a[i+2])            return 0*printf ("SEGMENT");    Return 0*printf ("impossible");}




CF 6A Triangle (determine if a triangle can be formed)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.