E - Triangle
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
4 2 1 3
TRIANGLE
7 2 2 4
SEGMENT
3 5 9 1
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的更多相关文章
- [LeetCode] Triangle 三角形
Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent n ...
- [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, ...
- [LeetCode] Pascal's Triangle 杨辉三角
Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5,Retur ...
- 【leetcode】Pascal's Triangle II
题目简述: Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Retur ...
- 【leetcode】Pascal's Triangle
题目简述: Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5 ...
- POJ 1163 The Triangle(简单动态规划)
http://poj.org/problem?id=1163 The Triangle Time Limit: 1000MS Memory Limit: 10000K Total Submissi ...
- Triangle - Delaunay Triangulator
Triangle - Delaunay Triangulator eryar@163.com Abstract. Triangle is a 2D quality mesh generator an ...
- LeetCode 118 Pascal's Triangle
Problem: Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows ...
- 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 ...
- 【leetcode】Triangle (#120)
Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent n ...
随机推荐
- CodeForces 546D
Description 两个士兵在玩一个游戏,开始的时候第一个士兵选择一个数n,并把这个数交给第二个士兵,第二个士兵必须选择一个x满足x>1 且n能被x整除,然后将n变为n/x,然后把这个数交给 ...
- web前端-雅虎34条规则优化
1.尽量减少HTTP请求次数 终端用户响应的时间中,有80%用于下载各项内容.这部分时间包括下载页面中的图像.样式表.脚本.Flash等.通过减少页面中的元素可以减少HTTP请求的次数.这是 ...
- 用 yo aspnet 生成.net项目
yo指的是Yeoman 官网:http://yeoman.io/ 因为安装yo需要nmp 因此 要先到node官网下载node并按装 安装之后就可以下一步了 $ npm install -g yo g ...
- 第一个Android crackme(2016-05)
第一个Android crackme 0x00 背景 最近在学习Android的逆向,把基本的环境搭好后,看了看<第一行代码--Android>,然后就按照非虫大牛的<Android ...
- LWP::UserAgent介绍1
require LWP::UserAgent; my $ua = LWP::UserAgent->new; ); $ua->env_proxy; my $response = $ua-&g ...
- (转载)uefi启动解析:由原理到实例
这是本文的全部内容:A:什么是UEFI,其含义B:UEFI模块包含的文件逐个分析及其引导流程+ESP分区的本质C:判断自己的机器是X64(64 bit)构架还是IA32(32 bit)的构架D:给传统 ...
- JavaBean的属性变量名前两个字母大小写问题
Java属性命名规范! 一般情况下.Java的属性变量名都已小写字母开头,如:userName,showMessage等,但也存在着特殊情况,考虑到一些特定的有意思的英文缩略词如(USA,XML等), ...
- CustomSummaryCalculate 用法
private void gridView1_CustomSummaryCalculate(object sender, DevExpress.Data.CustomSummaryEventArgs ...
- 分布式版本控制系统Git-----7.Git 使用git rebase合并多次commit
将多次commit合并,只保留一次提交历史. PS:在我练习的时候,将一个文件的代码做了多次修改,而且每次修改都给提交了,这几次改动的目的都一样,比如说修改RADEME.md,但是每次改动的只是一个小 ...
- Apache .htaccess语法之RewriteRule
[说明]定义重写的规则[语法]RewriteRule Pattern rewritePattern [flags] # 开启 rewrite 功能 Options +FollowSymlinks Re ...