博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
E - Triangle
阅读量:6855 次
发布时间:2019-06-26

本文共 2271 字,大约阅读时间需要 7 分钟。

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代码:

1 #include
2 #include
3 4 using namespace std; 5 int dp[6]={
0}; 6 int s[4]={
0}; 7 8 int gon() 9 {10 if(s[1]+s[2]>s[3]&&s[1]+s[3]>s[2]&&s[2]+s[3]>s[1])return 1;11 return 0;12 }13 int sa()14 {15 int i,j;16 int s;17 for(i=1;i<5;i++)18 for(j=i+1;j<5;j++){19 for(s=1;s<5;s++){20 if(s==i||s==j)continue;21 if(dp[i]+dp[j]==dp[s]){cout<<"SEGMENT"<
>dp[i];}52 sk();53 return 0;54 }
View Code

 

 

转载于:https://www.cnblogs.com/zhangchengbing/p/3233486.html

你可能感兴趣的文章
ucenter用户中心头像修改,不使用自带方法,不使用flash 转
查看>>
更改SQLServer实例默认字符集
查看>>
Ubuntu常用软件安装与使用
查看>>
Springboot 如何加密,以及利用Swagger2构建Restful API
查看>>
C++知识点总结(5)
查看>>
高性能Java科学与技术运算库Colt
查看>>
用前端将链接转为二维码,并下载
查看>>
nginx gzip压缩
查看>>
C#设计模式:模板方法模式(Template Method)
查看>>
SpringBoot项目以服务器方式启动
查看>>
静态文件
查看>>
centos永久修改主机名
查看>>
Objective-C
查看>>
在session状态中保存数据库数据
查看>>
论如何优雅的处理回文串 - 回文自动机详解
查看>>
Ubuntu16.04安装NVIDIA驱动时的一些坑与解决方案
查看>>
做一个完整的纯react-naitve安卓应用【从环境安装到应用发布】
查看>>
Maven工程的pom文件引用本地jar包
查看>>
When to Use Bar Charts Instead of Pie Charts
查看>>
打印出不同顺序的字符串&单引号和双引号的差异
查看>>