Page 3 of 3

Re: 10522 - Height to Area

Posted: Wed Feb 25, 2015 11:06 pm
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.

Re: 10522 - Height to Area

Posted: Fri Mar 20, 2015 10:25 pm
by coder.tanvir

Code: Select all

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

getting WA
working for sample i/o

Re: 10522 - Height to Area

Posted: Tue Mar 14, 2017 3:35 pm
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 
hold: 
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.