CF 6A Triangle (判断能否构成三角形)

Triangle

Time Limit: 2000ms

Memory Limit: 65536KB

This problem will be judged on CodeForces.
Original ID: 6A

64-bit integer IO format: %I64d     
Java class name: (Any)

Prev

Submit Status Statistics Discuss

Next

Type:

None

None Graph Theory 
    2-SAT     Articulation/Bridge/Biconnected Component
     Cycles/Topological Sorting/Strongly Connected Component
     Shortest Path 
        Bellman Ford         Dijkstra/Floyd Warshall
     Euler Trail/Circuit 
    Heavy-Light Decomposition     Minimum Spanning Tree
     Stable Marriage Problem 
    Trees     Directed Minimum Spanning Tree
     Flow/Matching 
        Graph Matching             Bipartite Matching
             Hopcroft–Karp Bipartite Matching
             Weighted Bipartite Matching/Hungarian Algorithm
         Flow 
            Max Flow/Min Cut             Min Cost Max Flow
 DFS-like 
    Backtracking with Pruning/Branch and Bound 
    Basic Recursion     IDA* Search 
    Parsing/Grammar     Breadth First Search/Depth First Search
     Advanced Search Techniques 
        Binary Search/Bisection         Ternary Search
 Geometry 
    Basic Geometry     Computational Geometry
     Convex Hull 
    Pick‘s Theorem Game Theory 
    Green Hackenbush/Colon Principle/Fusion Principle 
    Nim     Sprague-Grundy Number 
Matrix     Gaussian Elimination 
    Matrix Exponentiation Data Structures 
    Basic Data Structures     Binary Indexed Tree
     Binary Search Tree 
    Hashing     Orthogonal Range Search 
    Range Minimum Query/Lowest Common Ancestor 
    Segment Tree/Interval Tree     Trie Tree
     Sorting 
    Disjoint Set String 
    Aho Corasick     Knuth-Morris-Pratt 
    Suffix Array/Suffix Tree Math 
    Basic Math     Big Integer Arithmetic 
    Number Theory         Chinese Remainder Theorem
         Extended Euclid 
        Inclusion/Exclusion         Modular Arithmetic
     Combinatorics 
        Group Theory/Burnside‘s lemma         Counting
     Probability/Expected Value 
Others     Tricky 
    Hardest     Unusual 
    Brute Force     Implementation 
    Constructive Algorithms     Two Pointer 
    Bitmask     Beginner 
    Discrete Logarithm/Shank‘s Baby-step Giant-step Algorithm 
    Greedy     Divide and Conquer 
Dynamic Programming                  
Tag it!

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

Source

Codeforces Beta Round #6 (Div. 2 Only)

题意:给4条线段,问能否构成三角形,线段,或者不能构成三角形.

q神不愧是q神,参考了他的代码.

AC代码:

#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;
int main()
{
    int a[4];
    for(int i=0;i<4;i++)
        cin>>a[i];
    sort(a,a+4);
    for(int i=0;i<2;i++)
        if(a[i]+a[i+1]>a[i+2])
            return 0*printf("TRIANGLE");
    for(int i=0;i<2;i++)
        if(a[i]+a[i+1]==a[i+2])
            return 0*printf("SEGMENT");
    return 0*printf("IMPOSSIBLE");
}
时间: 2024-11-10 10:42:28

CF 6A Triangle (判断能否构成三角形)的相关文章

29.输入三个实数,判断能否构成三角形;若能,再说明是何种类型的三角形

#include<iostream> using namespace std; int main() { int a,b,c; cout<<"please input a,b and c : "<<endl; cin>>a>>b>>c; if((a+b<c)||(a+c<b)||(b+c<a)||(a-b>=c)||(a-c>=b)||(b-c>=a)||(b-a>=c)|

c语言:任给三条边长,判断能否构成三角形,如果能,求出其面积和周长

任给三条边长,判断能否构成三角形,如果能,求出其面积和周长 程序: #include<stdio.h> #include<math.h> int main() { double a, b, c, d, s, area; printf("请输入三个正数:"); scanf("%lf%lf%lf",&a,&b,&c); if ((a + b > c) && (a + c > b) &&a

【LeetCode-面试算法经典-Java实现】【119-Pascal&#39;s Triangle II(帕斯卡三角形(杨辉三角)II)】

[119-Pascal's Triangle II(帕斯卡三角形(杨辉三角)II)] [LeetCode-面试算法经典-Java实现][所有题目目录索引] 原题 Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Return [1,3,3,1]. Note: Could you optimize your algorithm to use only O(k) extra

LeetCode 119 Pascal&#39;s Triangle II(帕斯卡三角形II)(vector、数学公式)(*)

翻译 给定一个索引K,返回帕斯卡三角形的第K行. 例如,给定K=3, 返回[1,3,3,1]. 注释: 你可以改进你的算法只用O(k)的额外空间吗? 原文 Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Return [1,3,3,1]. Note: Could you optimize your algorithm to use only O(k) extra sp

[fzu 2273]判断两个三角形的位置关系

首先判断是否相交,就是枚举3*3对边的相交关系. 如果不相交,判断包含还是相离,就是判断点在三角形内还是三角形外.两边各判断一次. //http://acm.fzu.edu.cn/problem.php?pid=2273 #include<cstdio> #include<cmath> #include<cstring> #include<algorithm> using namespace std; const double eps=1e-8; const

二维平面上判断点在三角形内的最优算法

园子里有很多关于点是否在三角形内的文章,提供了各种方法.这让人很纠结,到底该用哪种算法?这里提供一套我认为最优的算法.如果你有不同的意见,亦或有更好的算法,欢迎来讨论. 算法使用的是同向法,其原理是:假设点P位于三角形ABC内,会有这样一个规律:三角形的每一个边,其对角点与P在边的同一侧:或者说三角形的每一个顶点与P在其对角边的同一侧. (1)代码 // 2D vector class Vec2 { public: Vec2() { x = 0.0f; y = 0.0f; } Vec2(floa

几种方法判断平面点在三角形内

最近在做一个Unity实现的3D建模软件,其中需要在模型表面进行操作的时候,需要用到点和三角形位置关系的判定算法.由于一个模型往往是几千个三角片,所以这个判定算法必须高效,否则会影响最终程序的整体性能.这里记录一下一些算法,如有误请指出,谢谢! 首先假设点和三角形在同一平面内,如果不在同一平面,需要用其它方法先筛选. 常用的几种平面点-三角形位置关系判定方法有(以下算法执行必须先保证点和三角形位于同平面): 1.顺时针/逆时针判定法 该方法要求点的顺序是顺时针或逆时针的,如果是顺时针的点,沿着3

判断点在三角形内部

利用叉积,如果点在三角形内部的话,则顺序处理全部边的话,这个点都在边的同一侧,直接用叉积判断 double det(double x1,double y1,double x2,double y2){ return x1*y2-x2*y1; } //x0,y0为需要的检查点,其他点顺时针顺序 bool check(double x0,double y0,double x1,double y1,double x2,double y2,double x3,double y3){ if(det(x0-x

ZOJ 3598 Spherical Triangle(计算几何 球面三角形内角和)

题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4682 As everybody knows, the sum of the interior angles of a triangle on a plane is always 180 degree. But this is not true when the triangle is on spherical surface. Given a triangle on