CodeForces 6A-Triangle(枚举/暴力)

简介: CodeForces 6A-Triangle(枚举/暴力)

题目描述:


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


7 2 2 4


3 5 9 1


(不是多实例,只是三组测试样例,需分别输入)


样例输出:


TRIANGLE


SEGMENT


IMPOSSIBLE  


解题思路:


翻译:给定 4 根木棍的长度,如果它们中存在 3 根木棍可以组成三角形,输出 TRIANGLE ;如果它们无法组成三角形,但是它们中存在 3 根木棍可以组成退化的三角形(任意两边之和大于等于第三边,但是不是三角形),输出 SEGMENT ;否则,输出 IMPOSSIBLE 。


输入:一行 4 个整数,4 根木棍的长度。


输出:如果它们中存在 3 根木棍可以组成三角形,输出 TRIANGLE ;如果它们无法组成三角形,但是它们中存在3根木棍可以组成退化的三角形,输出 SEGMENT ;否则,输出 IMPOSSIBLE。


直接暴力求解!!!看下面的代码:👇👇👇


AC Code:  


#include<bits/stdc++.h>
using namespace std;
int main() {
  int a[5];
  for(int i=1;i<=4;i++)
    scanf("%d",&a[i]);
  for(int i=1;i<=4;i++) {
    for(int j=1;j<=4&&j!=i;j++) {
      for(int k=1;k<=4&&k!=i&&k!=j;k++) {
        if(a[i]+a[j]>a[k]&&a[i]+a[k]>a[j]&&a[j]+a[k]>a[i]) {
          printf("TRIANGLE\n");
          return 0;
        }
      }
    }
  }
  for(int i=1;i<=4;i++) {
    for(int j=1;j<=4&&j!=i;j++) {
      for(int k=1;k<=4&&k!=i&&k!=j;k++) {
        if(a[i]+a[j]>=a[k]&&a[i]+a[k]>=a[j]&&a[j]+a[k]>=a[i]) {
          printf("SEGMENT\n");
          return 0;
        }
      }
    }
  }
  printf("IMPOSSIBLE\n");
  return 0;
}


相关文章
|
机器学习/深度学习 存储
light oj 1011 - Marriage Ceremonies (状态压缩+记忆化搜索)
light oj 1011 - Marriage Ceremonies (状态压缩+记忆化搜索)
41 0
A. Codeforces Checking(打表枚举)
A. Codeforces Checking(打表枚举)
52 0
codeforces144——D. Missile Silos(最短路+枚举)
codeforces144——D. Missile Silos(最短路+枚举)
94 0
codeforces144——D. Missile Silos(最短路+枚举)
Codeforces Round #434 (Div. 2, based on Technocup 2018 Elimination Round 1)&&Codeforces 861C Did you mean...【字符串枚举,暴力】
C. Did you mean... time limit per test:1 second memory limit per test:256 megabytes input:standard input output:standard out...
1124 0
|
人工智能 BI
Codeforces 834E The Bakery【枚举+数位dp】
E. Ever-Hungry Krakozyabra time limit per test:1 second memory limit per test:256 megabytes input:standard input output:stan...
1118 0
Codeforces Round #426 (Div. 2)【A.枚举,B.思维,C,二分+数学】
A. The Useless Toy time limit per test:1 second memory limit per test:256 megabytes input:standard input output:standard output ...
1182 0
|
人工智能 Go
POJ 1163 The Triangle【dp+杨辉三角加强版(递归)】
The Triangle Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 49955   Accepted: 30177 Description 73 88 1 0...
1014 0