Codeforces Beta Round #6 (Div. 2 Only)A. Triangle(暴力)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/sugarbliss/article/details/84992866

题目链接:http://codeforces.com/contest/6/problem/A

题意:给出四条木棍拿走其中任意一个,有三种情况:

  1. 能组成三角形就输出TRIANGLE。
  2. 最大边等于另外两边之和就输出SEGMENT。
  3. 都不行就输出IMPOSSIBLE。
#include<bits/stdc++.h>
using namespace std;
int a[4], b[3];
int main()
{
    for(int i = 0; i < 4; ++i)
        cin >> a[i];
    bool key_tr = false;
    bool key_sg = false;

    for(int i = 0; i < 4; ++i)
    {
        int cur = 0;
        for (int j = 0; j < 4; ++j)
        {
            if (j != i)
                b[cur++] = a[j];
        }
        sort (b, b + 3);
        if (b[0] + b[1] > b[2]) key_tr = true;
        if (b[0] + b[1] == b[2]) key_sg = true;
    }

    if (key_tr) cout << "TRIANGLE" << endl;
    else if (key_sg) cout << "SEGMENT" << endl;
    else cout << "IMPOSSIBLE" << endl;

    return 0;
}

猜你喜欢

转载自blog.csdn.net/sugarbliss/article/details/84992866