## 10522 - Height to Area

Moderator: Board moderators

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

### Re: 10522 - Height to Area

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!

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

### Re: 10522 - Height to Area

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

lighted
Guru
Posts: 585
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

### Re: 10522 - Height to Area

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)``