codeforces 6A. Triangle
2 seconds
64 megabytes
standard input
standard output
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
//1.能组成三角形2面积为0的三角形,即一条边等于另两条之和3:1,2都不满足
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int d[][3]={{0,1,2},{0,1,3},{0,2,3},{1,2,3}};
int a[4];
int fun(int *b){
if(a[b[0]]+a[b[1]]>a[b[2]]&&a[b[2]]+a[b[1]]>a[b[0]]&&a[b[0]]+a[b[2]]>a[b[1]])
if(a[b[0]]-a[b[1]]<a[b[2]]&&a[b[2]]-a[b[1]]<a[b[0]]&&a[b[0]]-a[b[2]]<a[b[1]])
return 1;
if(a[b[0]]+a[b[1]]==a[b[2]]||a[b[2]]+a[b[1]]==a[b[0]]||a[b[0]]+a[b[2]]==a[b[1]])
return 2;
return 0;
}
int main(){
int res,i;
while(~scanf("%d%d%d%d",&a[0],&a[1],&a[2],&a[3])){
for(res=i=0;i<4;i++){
int k=fun(d[i]);
if(k==1){res=-1;printf("TRIANGLE\n");break;}
else if(k==2)res=k;
}
if(res==2)printf("SEGMENT\n");
else if(res==0)printf("IMPOSSIBLE\n");
}
return 0;
}
codeforces 6A. Triangle的更多相关文章
- CodeForces 239A. Triangle
Link: http://codeforces.com/contest/407/problem/A 给定直角三角形的2个直角边a,b.求在直角坐标系中,是否存在对应的直角三角形,使得三个定点都在整点 ...
- codeforces C. Triangle
C. Triangle time limit per test 1 second memory limit per test 256 megabytes input standard input ou ...
- CodeForces - 18A Triangle(数学?)
传送门 题意: 给出三个点的坐标,初始,这三个点可以构成一个三角形. 如果初始坐标可以构成直角三角形,输出"RIGNT". 如果某个点的 x或y 坐标移动一个单位后可以组成直角三角 ...
- [Codeforces 15E] Triangle
Brief Introduction: 求从N出发,回到N且不包含任何黑色三角的路径数 Algorithm:假设从N点到第二层中间的节点M的路径数为k,易知总路径数为(k*k+1)*2 而从第第四层开 ...
- Codeforces Round #396 (Div. 2) B. Mahmoud and a Triangle 贪心
B. Mahmoud and a Triangle 题目连接: http://codeforces.com/contest/766/problem/B Description Mahmoud has ...
- Codeforces Beta Round #6 (Div. 2 Only) A. Triangle 水题
A. Triangle 题目连接: http://codeforces.com/contest/6/problem/A Description Johnny has a younger sister ...
- Codeforces Round #396 (Div. 2) A - Mahmoud and Longest Uncommon Subsequence B - Mahmoud and a Triangle
地址:http://codeforces.com/contest/766/problem/A A题: A. Mahmoud and Longest Uncommon Subsequence time ...
- 【codeforces 766B】Mahmoud and a Triangle
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- codeforces A. Vasily the Bear and Triangle 解题报告
题目链接:http://codeforces.com/problemset/problem/336/A 好简单的一条数学题,是8月9日的.比赛中没有做出来,今天看,从pupil变成Newbie了,那个 ...
随机推荐
- ShellExecute函数简单说明
平时在delphi写代码的过程中总是能遇到ShellExecute函数,于是索性将它的使用方法整理一下,由于我在微软的站点上也没能查到个详解(当然我查的中文版,俺菜嘛) ShellExecute函数原 ...
- 实现一个简单的Unity3D三皮卡——3D Picking (1)
3D Picking 其原理是从摄像机位置到空间发射的射线.基于光线碰到物体回暖. 这里我们使用了触摸屏拿起触摸,鼠标选择相同的原理,仅仅是可选API不同. 从unity3D官网Manual里找到下面 ...
- 用javascript把扑克牌理理顺!
打扑克的人都知道,比如斗地主! 我们一般都会按照顺序把随机摸过来的牌从小到大的顺序在手上理整齐(记得小时候打牌两副牌手都抓不过来),这篇随笔就是想通过实现这个功能来熟悉下js中排序数组等相关知识. 用 ...
- ASP.NET抓取网页内容
原文:ASP.NET抓取网页内容 一.ASP.NET 使用HttpWebRequest抓取网页内容 这种方式抓取某些页面会失败 不过,有时候我们会发现,这个程序在抓取某些页面时,是获不到所需的内容的, ...
- 《Programming Hive》读书笔记(两)Hive基础知识
<Programming Hive>读书笔记(两)Hive基础知识 :第一遍读是浏览.建立知识索引,由于有些知识不一定能用到,知道就好.感兴趣的部分能够多研究. 以后用的时候再具体看.并结 ...
- lsof基本使用
当你想在计算机上启动一个服务,电脑已经建议"port already in use",此时,可以使用lsof命令查看占用端口的进程(lsof -i:port). lsof这是LiS ...
- 【AngularJS】 2.0 版本发布
[AngularJS] 2.0 版本发布 w5cValidator[AngularJS] 2.0 版本发布 w5cValidator 插件基于angular原有的表单验证,在原有的基础上扩展了一些 ...
- AngularJS Change Path Without Reloading
To change path URL with AngularJS, $location.path() is passed the new URL as a parameter, and the pa ...
- Python的@符号
Python一直都属于用,没有去系统学习过,在一次代码review中见到了@符号,回来看了下,这个符号用于装饰器中,用于修饰一个函数,把被修饰的函数作为参数传递给装饰器,下面举几个例子: 1. @cl ...
- .net开发框架设计
转WisDom .net开发框架设计 WisDom .net 框架设计 1. 为啥要弄 2014 年我已经是我们参加工作的第六年,也做过不少项目,但是发现自己没有代码积累.这里利用业余时间梳理一下 ...