HUST 1555 A Math Homework

简介: 1555 - A Math Homework 时间限制:1秒 内存限制:128兆 338 次提交 131 次通过 题目描述     QKL is a poor and busy guy, and he was not good at math.

1555 - A Math Homework

时间限制:1秒 内存限制:128兆

338 次提交 131 次通过
题目描述
     QKL is a poor and busy guy, and he was not good at math. 
    Last day, his teacher assigned a homework: Give you 3 segments with positive length, can you use these segments to make a triangle? If can, what is the type of the triangle? Acute triangle, right triangle or obtuse triangle? Pay attention that vertices of triangle must be vertices of two segments.
     QKL is afraid of any type of math problems, so he turns to you for help. Can you help him?
输入
Several test cases, one line per case.
In case consists of three positive integers: a, b, c, indicating the lengths of 3 segments.
0 < a, b, c <= 10000
输出
In each test case, you just print one line of result.
If you can't make a triangle by using these segments, print "FAIL TO MAKE!"(quote for clarify).
If you can make an acute triangle, print "Acute"(quote for clarify).
If you can make a right triangle, print "Right"(quote for clarify).
If you can make an obtuse triangle, print "Obtuse"(quote for clarify).
样例输入
1 2 3
2 3 4
3 4 5
4 5 6
样例输出
FAIL TO MAKE!
Obtuse
Right
Acute
提示
You can use this form of code to deal with several test cases.
 
while ( scanf("%d%d%d", &a, &b, &c) != EOF)
{
//Your codes here.
}
分析:题目大意就是求解三边是否构成三角形,如果是,它是钝角三角形、锐角三角形还是直角三角形!
别看如此简单,出题目的人挖空心思在坑人!提示告诉我们要用scanf输入,不然估计又会超时吧!
刚开始想用数组输,结果可想而知,直接WA,其实这题目也没有那么复杂,就是先去判断三边是否构成三角形,然后利用余弦定理(判断任意两边的平方和减去第三边的大小情况)大于0为锐角三角形,小于0为钝角三角形,等于0为直角三角形!
也可以将这三条边进行排序,然后取最短两条边的平方和与第三边的平方进行比较求解!
下面给出AC代码:
 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 int main()
 4 {
 5     int a,b,c;
 6     double s;
 7     while(scanf("%d%d%d",&a,&b,&c)!=EOF)
 8     {
 9         if(a+b<=c||a+c<=b||b+c<=a)
10          printf("FAIL TO MAKE!\n");
11         else
12         {
13             if(a*a+b*b-c*c==0||a*a+c*c-b*b==0||b*b+c*c-a*a==0)
14                printf("Right\n");
15                else if(a*a+b*b-c*c<0||a*a+c*c-b*b<0||b*b+c*c-a*a<0)
16                 printf("Obtuse\n");
17                else printf("Acute\n");
18         }
19     }
20     return 0;
21 }

 

目录
相关文章
|
3天前
|
Java 编译器
Java Number & Math 类
4月更文挑战第12天
|
3天前
Math常用方法,什么是math?
Math常用方法,什么是math?
18 0
|
3天前
|
Java
Java——Math、BigInteger和Random类
Java——Math、BigInteger和Random类
18 0
|
9月前
|
Java
Math类
Math类
40 0
|
8月前
Math方法的使用
Math方法的使用
28 0
|
JavaScript 前端开发
Math.random();
Math.random();
63 0
java 中的 Math.round(-1.5) 等于多少
java 中的 Math.round(-1.5) 等于多少
|
算法 Java
Java求数的平方根,不使用Math.sqrt
题目,给一个整数,求它的平方根,不能使用java自带的Math.sqrt(); 平方根就是开平方,比如4的平方根是2,100的平方根是10;
238 0
|
算法 机器学习/深度学习
Math
机器学习中的数学基础 微分学 求导数 求偏导数 以上两个通过公式或者使用泰勒公式进行逼近得到的 求f(x)在x0处的导数 根据泰勒公式: f(x) = f(x0) + f'(x0)(x - x0) + f''(x0)(x - x0)^2/2! + f'''(x0)(x - x0)^3/3! + .
897 0