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.

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.

}

题目链接:http://acm.hust.edu.cn/problem/show/1555

分析:题目大意就是求解三边是否构成三角形,如果是,它是钝角三角形、锐角三角形还是直角三角形!

别看如此简单,出题目的人挖空心思在坑人!提示告诉我们要用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 }
时间: 2024-12-25 22:01:50

HUST 1555 A Math Homework的相关文章

BestCoder Round #29——A--GTY&#39;s math problem(快速幂(对数法))、B--GTY&#39;s birthday gift(矩阵快速幂)

GTY's math problem Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 0    Accepted Submission(s): 0 Problem Description GTY is a GodBull who will get an Au in NOI . To have more time to learn alg

BestCoder Round #29 1001 GTY&#39;s math problem

GTY's math problem Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 0    Accepted Submission(s): 0 Problem Description GTY is a GodBull who will get an Au in NOI . To have more time to learn alg

HDU 5170 GTY&#39;s math problem (bsst code #29 1001)

GTY's math problem Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 146    Accepted Submission(s): 80 Problem Description GTY is a GodBull who will get an Au in NOI . To have more time to learn

HDU 5170 GTY&#39;s math problem 精度判断问题

传送门 GTY's math problem Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 568    Accepted Submission(s): 263 Problem Description GTY is a GodBull who will get an Au in NOI . To have more time to l

[SinGuLaRiTy] COCI 2011~2012 #2

[SinGuLaRiTy-1007] Copyright (c) SinGuLaRiTy 2017. All Rights Reserved. 测试题目 对于所有的题目:Time Limit:1s  |  Memory:256 MB 第一题:考试得分(score)[najboljih] [题目描述] 某单位举办了一次考试,考试有8道题,每道题的得分不一样.选手可以随便做,但最后只统计5道题的得分.现在给出选手每道题的得分,求出他最后的得分最大是多少? [输入] 8行,每行一个正整数X(0<=X<

Codeforces #264 (Div. 2) D. Gargari and Permutations

Gargari got bored to play with the bishops and now, after solving the problem about them, he is trying to do math homework. In a math book he have found k permutations. Each of them consists of numbers 1,?2,?...,?n in some order. Now he should find t

你在工作中无意间会犯的四个错误

4 Work Mistakes You Don't Realize You're Making你在工作中无意间会犯的四个错误When you’re the new girl at work, you do everything in your power to stay on your best behavior. You show up to the office early, leave late, dress conservatively, and absolutely never, ev

Chapter 2 Open Book——14

I backpedaled. "They seemed nice enough to me. I just noticed they keptto themselves. 我改口说道,他们看起来对我来说不错,我只是注意到他们总是独来独往. They're all very attractive," I added, trying to be more complimentary. 他们都很有引人注意.我补充到,尝试表达的更赞美些. "You should see the do

hdu 4983 Goffi and GCD(欧拉函数)

Problem Description Goffi is doing his math homework and he finds an equality on his text book: gcd(n−a,n)×gcd(n−b,n)=nk. Goffi wants to know the number of (a,b) satisfy the equality, if n and k are given and 1≤a,b≤n. Note: gcd(a,b) means greatest co