Description

Johnny has a younger sister Anne, who is very clever and smart. As she came home from the kindergarten, she told his brother about the task that her 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 allowed to break the sticks or use their partial length. Anne has perfectly solved this task, now she is asking Johnny to do the same.

The boy answered that he would cope with it without any difficulty. However, after a while he found out that different tricky things can occur. It can happen that it is impossible to construct a triangle of a positive area, but it is possible to construct a degenerate triangle. It can be so, that it is 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 you to help him.

Input

The first line of the input contains four space-separated positive integer numbers not exceeding 100 — lengthes of the sticks.

Output

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

Sample Input

Input
4 2 1 3
Output
TRIANGLE
Input
7 2 2 4
Output
SEGMENT
Input
3 5 9 1
Output
IMPOSSIBLE

题意:

给出四个整数如果存在三个数能构成一个三角形,则输出TRIANGLE,如果任何三个数都不能构成三角形,但是存在三个数可构成退化三角形,则输出SEGMENT,如果任何三个数既不能构成三角形也不能构成退化三角形,则输出IMPOSSIBLE

退化三角形:三条边,不可以组成三角形,但是存在两条边的和等于第三条边;

AC代码:

 #include<iostream>
#include<cstdio> using namespace std;
int dp[]={};
int s[]={}; int gon()
{
if(s[]+s[]>s[]&&s[]+s[]>s[]&&s[]+s[]>s[])return ;
return ;
}
int sa()
{
int i,j;
int s;
for(i=;i<;i++)
for(j=i+;j<;j++){
for(s=;s<;s++){
if(s==i||s==j)continue;
if(dp[i]+dp[j]==dp[s]){cout<<"SEGMENT"<<endl;return ;}
}
}
return ;
}
int sk()
{
int i,j;
int a=;;
for(i=;i<;i++){
a=;
for(j=;j<;j++){
if(j!=i){
s[a++]=dp[j];
if(a==){
if(gon()==){cout<<"TRIANGLE"<<endl;return ;}
break;
}
}
}
}
if(sa()==)return ;
cout<<"IMPOSSIBLE"<<endl;
return ;
} int main()
{
int i;
for(i=;i<;i++){cin>>dp[i];}
sk();
return ;
}

E - Triangle的更多相关文章

  1. [LeetCode] Triangle 三角形

    Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent n ...

  2. [LeetCode] Pascal's Triangle II 杨辉三角之二

    Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Return [1,3, ...

  3. [LeetCode] Pascal's Triangle 杨辉三角

    Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5,Retur ...

  4. 【leetcode】Pascal's Triangle II

    题目简述: Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Retur ...

  5. 【leetcode】Pascal's Triangle

    题目简述: Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5 ...

  6. POJ 1163 The Triangle(简单动态规划)

    http://poj.org/problem?id=1163 The Triangle Time Limit: 1000MS   Memory Limit: 10000K Total Submissi ...

  7. Triangle - Delaunay Triangulator

    Triangle - Delaunay Triangulator  eryar@163.com Abstract. Triangle is a 2D quality mesh generator an ...

  8. LeetCode 118 Pascal's Triangle

    Problem: Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows  ...

  9. LeetCode 119 Pascal's Triangle II

    Problem: Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Ret ...

  10. 【leetcode】Triangle (#120)

    Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent n ...

随机推荐

  1. git 基本的操作

      查看分支:git branch   查看所有分支:git branch -a   删除分支:git branch -d <name>   创建分支:git branch <nam ...

  2. ubuntu配置LAMP

    1.安装Apache sudo apt-get install apache2 如果显示未找到软件则执行sudo apt-get update(建议使用ubuntu正在支持的系统版本,不在支持的版本可 ...

  3. 正确的IP地址正则表达式

    ((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\d\d?)

  4. Java中eclipse中添加源码依赖

    Window ->Preferences ->Java->instanlled jres  ->editrt.jarsource attachment一般在jdk的目录下的sr ...

  5. pro asp.net mvc5 7

    一个类可以依靠IProductRepository这一接口获取Product对象,而不必知道这些对象从哪里来,也不必知道该接口的实现类如何递交这些对象,这就是存储库模式的本质

  6. php 分析

    php  code in D:\10\11\php test in D:\10\11\php\test issue 1: <html><head><title>标记 ...

  7. 为什么重写equals()必须重写hashCode()

    主要原因是因为hashCode是用对象的内部地址转换成一个整数的,而equals比较得是两个对象,或者是两个对象的内容 如果你重写了equals,而保留hashCode的实现不变,那么很可能两个对象明 ...

  8. iOS 打包上传AppStore相关(3)-iTunes相应配置以及使用蒲公英网站进行应用托管分发(链接/二维码)

    上一篇讲到我们最终生成了一个格式为 .xcarchive 的文件(可以右键并Show in Finder)查看.本篇我们就进行最后的设置,打包上传.另外,还有一个小福利,那就是打测试包分发链接测试. ...

  9. Linux常用命令汇总及使用方法(二)之文本编辑器VI

    VI可能是在Linux中使用比较频繁的文本编辑器,如果不能熟练使用VI,在一定程度上会影响工作效率,所以在这里记录一下VI的常用命令及操作方式 在[root@test ~]# vi carrie.tx ...

  10. C#读取Excel的其中一种方式OleDb读取(100万条)--快速大量插入SQL中

    主要运用表类型 Create table BulkTestTable( Id nvarchar(), UserName nvarchar(), Pwd nvarchar() ) Go CREATE T ...