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. javascript和jquery比较中学习

    获取input的值: document.getElementById("id").value;这里查的是input的name属性 $('input').val(); 设置input ...

  2. vim的配置文件参数

    环境:kali linux vim的配置文件存放在/etc/vim目录中,配置文件名为vimrc set nocompatible "去掉有关vi一致性模式,避免以前版本的bug和局限&qu ...

  3. 干货篇:揭开CSS盒模型神秘的面纱

    写博客可以对学习内容进行总结.分享和交流(面对面的技术分享会也不错)... 如果是单纯的记录,印象笔记完全够了. 步入正题,盒模型是web布局核心,掌握基础知识,以后实战中会如鱼得水~ 概念与历史 C ...

  4. ios 关于tableview小技巧

    第一个:cell中的分割线不顶头 首先在viewDidLoad方法加入以下代码: if ([self.tableView respondsToSelector:@selector(setSeparat ...

  5. Mac下如何使用Vim

    帖子是转载的,原帖地址 Mac OX其实已经默认装好了vim了.不需要再安装Macvim https://ruby-china.org/topics/4905 Mac开发利器之程序员编辑器MacVim ...

  6. linux 调整文件系统大小 LVM

    fuser -m /home umount /home lvreduce -L 150G /dev/mapper/centos-home lvextend -L +300G /dev/mapper/c ...

  7. 删除和创建ms sql的分区文件

    今天测试ms sql 的表分区的时候,不小心搞错了分区的条件.然后我想重新做一次,操作流程如下(按顺序) 1:删除SCHEME DROP  PARTITION SCHEME TestSPScheme ...

  8. mysql修改编码

    1.查看当前编码 2.设置utf8mb4编码(也可以是其他),修改my.cnf或my.ini

  9. pre标签

    $(" .pop-info").html("<PRE>"+data.info+"<PRE>"): 数据库里的换行存的 ...

  10. Ubuntu14.04安装完全分布式Hadoop1.2.1

    一直想装hadoop集群,但总是没有时间,最近抽了三天时间下定决定装了一下,在我的wmware上虚拟了一台Ubuntu14.04,然后再复制了两台虚拟机,准备开始!!!! 基本参考 http://ww ...