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;
}


相关文章
|
人工智能
Codeforces1343D - Constant Palindrome Sum + UPC-鸭子游戏 (差分)
Codeforces1343D - Constant Palindrome Sum + UPC-鸭子游戏 (差分)
112 1
codeforces144——D. Missile Silos(最短路+枚举)
codeforces144——D. Missile Silos(最短路+枚举)
108 0
codeforces144——D. Missile Silos(最短路+枚举)
|
人工智能
Codeforces 220B-Little Elephant and Array-扫描线 & 树状数组
题意: 给出一个长度为n的数组,有m个询问,每次询问给出一个区间,问这个区间内有多少个数x恰好出现x次
136 0
Codeforces 220B-Little Elephant and Array-扫描线 & 树状数组
|
机器学习/深度学习
CodeForces 629A-Far Relative’s Birthday Cake(枚举/暴力)
CodeForces 629A-Far Relative’s Birthday Cake(枚举/暴力)
[USACO | UPC] Liars and Truth Tellers | 拓展域并查集
题目描述 After spending so much time around his cows, Farmer John has started to understand their language. Moreover, he notices that among his N cows (2 ≤ N ≤ 1000 ), some always tell the truth while others always lie.
141 0
【1105】Spiral Matrix (25分)【螺旋矩阵】
【1105】Spiral Matrix (25分)【螺旋矩阵】 【1105】Spiral Matrix (25分)【螺旋矩阵】
131 0
|
容器
零元学Expression Blend 4 - Chapter 4元件重复运用的观念
原文:零元学Expression Blend 4 - Chapter 4元件重复运用的观念 本章将教大家Blend元件重复运用的观念,这在Silverlight设计中是非常重要的,另外加码赠送渐层工具(Gradient Tool)。
1195 0