给定三条边,请你判断一下能不能组成一个三角形。
Input
输入数据第一行包含一个数M,接下有M行,每行一个实例,包含三个正数A,B,C。其中A,B,C <1000;
Output
对于每个测试实例,如果三条边长A,B,C能组成三角形的话,输出YES,否则NO。
Sample Input
2
1 2 3
2 2 2
Sample Output
NO
YES
思路:任意两边之和大于第三边,任意两边之差小于第三边
#include <iostream>
#include<algorithm>
#include<iomanip>
using namespace std;
int main()
{
int t;
double a[3];
cin >> t;
while (t--)
{
cin >> a[0] >> a[1] >> a[2];
if (a[0] + a[1] > a[2] && a[0] + a[2] > a[3] && a[1] + a[2] > a[0]&&abs(a[0]-a[1])<a[2] && abs(a[0] - a[2]) < a[1] && abs(a[2] - a[1]) < a[0]) puts("YES");
else puts("NO");
}
}