10522 - Height to Area

All about problems in Volume 105. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10522 - Height to Area

Post by brianfry713 »

Try using a EPS of 1e-8.

If fabs(Ha) < EPS then it's invalid, similar for Hb and Hc.

If the sqrt() part is < EPS then it's invalid.
Check input and AC output for thousands of problems on uDebug!

New poster
Posts: 11
Joined: Mon Mar 09, 2015 10:30 am

Re: 10522 - Height to Area

Post by coder.tanvir »

Code: Select all

#include <stdio.h>
#define EPS 1e-18
int main()
    int ca;
         long double Ha,Hb,Hc,area;
         scanf("%Lf %Lf %Lf",&Ha,&Hb,&Hc);
        if(area<EPS) {
            printf("These are invalid inputs!\n");
        else {
    return 0;

getting WA
working for sample i/o

Posts: 587
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

Re: 10522 - Height to Area

Post by lighted »

Sedefcho wrote:
Tue Mar 01, 2005 6:41 pm
Given three real numbers ( double, long double numbers
in terms of C++ ) Ha, Hb, Hc we can state the following :

Code: Select all

Ha, Hb, Hc are valid lengths of heights/altitudes of a 
non-degenerate triangle if and only if the following conditions 
1) Ha, Hb, Hc are all positive 
2)  1/Ha + 1/Hb - 1/Hc > 0 
3)  1/Ha - 1/Hb + 1/Hc > 0 
4) -1/Ha + 1/Hb + 1/Hc > 0 
I leave to you how to express these conditions in C++ or some
other programming language.

And one more thing: I have used this condition in my ACC program
so at least for this problem you can assume this is the condition.

I am sure that purely from a mathematical point of view,
this is also the true IF-AND-ONLY-IF statement.

I think problem is in your checking invalid inputs. When i changed it to

Code: Select all

if (1/Ha < 1/Hb + 1/Hc  &&  1/Hb < 1/Ha + 1/Hc  &&  1/Hc < 1/Ha + 1/Hb)
Your code get accepted.
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman

Post Reply

Return to “Volume 105 (10500-10599)”