您的位置:首页 > 其它

HDU 2393 Higher Math

2016-01-18 20:17 232 查看

Higher Math

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 2972    Accepted Submission(s): 1580


[align=left]Problem Description[/align]
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.

 

[align=left]Input[/align]
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.

 

[align=left]Output[/align]
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.

 

[align=left]Sample Input[/align]

2
36 77 85
40 55 69

 

[align=left]Sample Output[/align]

Scenario #1:
yes

Scenario #2:
no

分析:该题要判断三边组成的三角形是否为直角三角形。格式要求每个示例后面有一个空行

代码如下:

#include <stdio.h>
void swap(int &a,int &b,int &c)
{
int temp;
if(a>b)
{
temp=a;
a=b;
b=temp;
}
if(a>c)
{
temp=c;
c=a;
a=temp;
}
if(b>c)
{
temp=b;
b=c;
c=temp;
}
}

int main()
{
int n;
int i,j;
int a,b,c;
scanf("%d",&n);
for(i=1;i<=n;i++)
{
scanf("%d %d %d",&a,&b,&c);
printf("Scenario #%d:\n",i);
swap(a,b,c);
if(a*a+b*b==c*c)
printf("yes\n");
else
printf("no\n");
putchar('\n');
}

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  直角三角形