[HDU] [2039] Triangle

Problem Description

Loading...

Problem Analysis

A simpler sort
It uses the method I saw before learning bubble sort
for sorting three numbers
After sorting, just check whether the sum of two sides is greater than the third side

cpp
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include<stdio.h>
int main() {
	int n;
	double t,a,b,c;
	scanf("%d",&n);
	while(n) {
		scanf("%lf %lf %lf",&a,&b,&c);
		if(a>b) {
			t=a;
			a=b;
			b=t;
		}
		if(b>c) {
			t=b;
			b=c;
			c=t;
		}
		if(a>b) {
			t=a;
			a=b;
			b=t;
		}
		if(a+b>c)
		printf("YES\n");
		else
		printf("NO\n");
		n--;
	}
	return 0;
}

Loading...