hdu 2393(Higher Math)

来源:互联网 发布:期货软件开发公司 编辑:程序博客网 时间:2024/05/16 06:00


Higher Math(原网址:http://acm.hdu.edu.cn/showproblem.php?pid=2393

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2758    Accepted Submission(s): 1484


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
236 77 8540 55 69


Sample Output
Scenario #1:yesScenario #2:no




题意:

给你一个数字n,随后有n组数据。每一组数据有3个正整数。判断以这三个正整数为边长构成的三角形是否为直角三角形。是则输出“Scenario #i(i为当前组数):(换行)yes”。否则输出“Scenario #i(i为当前组数):(换行)no”。(n组数据)




参考代码:

#include<iostream>using namespace std;int main(){    int a,b,c,n,i,a1,b1,c1;    cin>>n;    for(i=0;i<n;i++)    {        cin>>a>>b>>c;        a1=a*a;        b1=b*b;        c1=c*c;        printf("Scenario #%d:\n",i+1);        if(a1+b1==c1 || a1+c1==b1 || b1+c1==a1)            cout<<"yes"<<endl<<endl;        else            cout<<"no"<<endl<<endl;    }    return 0;}



运行结果:

Accepted23930MS1944K400B




题解:

难点在判断三角形是否为直角三角形。根据勾股定理逆定理(勾股定理逆定理:如果三角形三边长a,b,c满足

,那么这个三角形是直角三角形)可解。

本题中不保证第一、二个数为直角边,所以满足a的平方+b的平方=c的平方;a的平方+c的平方=b的平方;b的平方+c的平方=a的平方之一的三角形即为直角三角形。

注:输出格式一定不要错。




参考知识:

勾股定理(Pythagoras theorem)——》百度。



0 0
原创粉丝点击