2014
01-05

# Higher Math

You are building a house. You’d prefer if all the walls have a precise right angle relative to the ground, but you have no device to measure angles. A friend says he has a great idea how you could ensure that all walls are upright: All you need to do is step away a few feet from the wall, measure how far away you are from the wall, measure the height of the wall, and the distance from the upper edge of the wall to where you stand. You friend tells you to do these measurements for all walls, then he’ll tell you how to proceed. Sadly, just as you are done, a timber falls on your friend, and an ambulance brings him to the hospital. This is too bad, because now you have to figure out what to do with your measurements yourself.

Given the three sides of a triangle, determine if the triangle is a right triangle, i.e. if one of the triangle’s angles is 90 degrees.

The inputs start with a line containing a single integer n. Each of the n following lines contains one test case. Each test case consists of three integers 1 <= a, b, c <= 40000 separated by a space. The three integers are the lengths of the sides of a triangle.

The inputs start with a line containing a single integer n. Each of the n following lines contains one test case. Each test case consists of three integers 1 <= a, b, c <= 40000 separated by a space. The three integers are the lengths of the sides of a triangle.

2
36 77 85
40 55 69

Scenario #1:
yes

Scenario #2:
no

mark：勾股定理，最大边40000，运算中间数最大是3.2*10^9，比int的上界2.2*10^10小，因此不用担心溢出。

# include <stdio.h>

int main ()
{
int T, a, b, c ;
int nCase = 1 ;
scanf ("%d", &T) ;
while (T--)
{
scanf ("%d%d%d", &a, &b, &c) ;
if (a*a+b*b==c*c || a*a+c*c==b*b || b*b+c*c==a*a)
printf ("Scenario #%d:\nyes\n\n", nCase++) ;
else
printf ("Scenario #%d:\nno\n\n", nCase++) ;
}
return 0 ;
}

1. 给你一组数据吧：29 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 1000。此时的数据量还是很小的，耗时却不短。这种方法确实可以，当然或许还有其他的优化方案，但是优化只能针对某些数据，不太可能在所有情况下都能在可接受的时间内求解出答案。