HDOJ 2393. Higher Math

Higher Math

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2853    Accepted Submission(s): 1525
Problem Description
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.
 
Input
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.
 
Output
The output for every scenario begins with a line containing “Scenario #i:”, where i is the number of the scenario counting from 1. After that, output a single line containing either the string “yes” or the string “no”, depending on if the triangle in this test case has a right angle. Terminate each test case with an empty line.
 
Sample Input
2 36 77 85 40 55 69
 
Sample Output
Scenario #1: yes Scenario #2: no
 
Source
 
 
        简单水题,前面瞎扯了一大段,然后就是给你三角形三条边长,判断能不能构成直角。
        把最长的边选出来,排序或者if乱搞都行。注意每个case后面输出一个空行。
 1 #include <iostream>
 2 #include <algorithm>
 3 using namespace std;
 4 int main()
 5 {
 6     long n,s[3],cnt=0;
 7     cin>>n;
 8     while(n--)
 9     {
10         cin>>s[0]>>s[1]>>s[2];
11         cout<<"Scenario #"<<++cnt<<':'<<endl;
12         s[0]*=s[0];
13         s[1]*=s[1];
14         s[2]*=s[2];
15         sort(s,s+3);
16         if(s[2]==s[0]+s[1])
17             cout<<"yes";
18         else
19             cout<<"no";
20         cout<<endl<<endl;
21     }
22     return 0;
23 }

 

原文地址:https://www.cnblogs.com/BlackStorm/p/4940775.html