A. Triangle
来源:互联网 发布:新手开淘宝网店 编辑:程序博客网 时间:2024/05/18 18:03
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.
The first line of the input contains four space-separated positive integer numbers not exceeding 100 — lengthes of the sticks.
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.
4 2 1 3
TRIANGLE
7 2 2 4
SEGMENT
3 5 9 1
IMPOSSIBLE
解题说明:此题就是判断从4根棍子中选择3根是否能够构成三角形,至于三角形这里有普通三角形和退化三角形之分,退化三角形解释如下:
退化三角形(degenerate triangle)是个面积为零的三角形,或换句话说,是个三点位于一线上的三角形。如果我们传入一个退化三角形到渲染管线,则该三角形显示为空。
做法是先对输入线段排序,然后分情况判断即可。
#include<iostream>#include<map>#include<string>#include<algorithm>#include<cstdio>#include<cmath>using namespace std;int main(){ int i,a[4]; for(i=0;i<4;i++){scanf("%d",&a[i]);}sort(a,a+4); if(a[0]+a[1]>a[2]||a[1]+a[2]>a[3]){printf("TRIANGLE\n");} else if(a[0]+a[1]==a[2]||a[1]+a[2]==a[3]) { printf("SEGMENT\n");}else{printf("IMPOSSIBLE\n");}return 0;}
- A. Triangle
- A. Triangle
- Rendering a triangle
- CF 6 A - Triangle
- HDU3188:Just A Triangle
- codeforces Round6 A. Triangle
- codeforces 18A - Triangle
- codeforces 6A. Triangle
- Just A Triangle
- sgu151 Construct a triangle
- CF 407A - Triangle
- CF 407A Triangle
- CodeForces 407A Triangle
- CodeForces 407A Triangle
- CodeForces 407A Triangle
- codeforces 6A Triangle
- CodeForces 407A Triangle
- sgu151:Construct a triangle
- DLL传递字符串数组输出参数
- 尝试加载 Oracle 客户端库时引发 BadImageFormatException。如果在安装 32 位 Oracle 客户端组件的情况下以 64 位模式运行,将出现此问题
- fedora 18 图文安装教程
- const的用法
- android中在指定的界面中插入引导页
- A. Triangle
- Flex开发ArcGIS问题集锦六:怎样使用空间引用
- C#下调用捷宝链接库函数整理
- 在jsp文件中调用自定义控件(如果不存在,自动下载CAB文件安装注册)
- PhoneGap API介绍:Connection
- 软件开发基本原则一------典型错误
- SQLServer sa登陆失败
- IO_缓冲和非缓冲
- AIDL