Page **2** of **3**

Posted: **Thu Oct 23, 2003 10:41 am**

by **Maarten**

negative heights ??? what the hell does that mean?

and when two of ha, hb, and hc are zero, then we have no triangle but something like a line, which obviously has are 0.000. I don't think it is invalid input. However, when only one of ha, hb, hc is zero, then the input is invalid.

Am I right here ?

### ya

Posted: **Fri Oct 24, 2003 10:44 am**

by **nonstop**

Maarten wrote:negative heights ??? what the hell does that mean?

and when two of ha, hb, and hc are zero, then we have no triangle but something like a line, which obviously has are 0.000. I don't think it is invalid input. However, when only one of ha, hb, hc is zero, then the input is invalid.

Am I right here ?

ya...i am wondering whether area=o is valid or not.

Maarten, do you ever think of triangle abc:

ab>ac-bc, ab<ac+bc........like this condition????

i've noticed this, but still W.A.....

is it the problem of precision????

for all variable are floating type or double type....

Posted: **Fri Oct 24, 2003 10:53 am**

by **Maarten**

never mind me.. i made a stupid mistake:

[cpp] else if( ha == 0.0 || hb == 0.0 )

printf( "These are invalid inputs!\n" );

else {

[/cpp]

it should be

[cpp] else if( ha == 0.0 || hb == 0.0 ) **{**

printf( "These are invalid inputs!\n" );

**i++;**

**}** else {

[/cpp]

Posted: **Sat Oct 25, 2003 2:32 pm**

by **Towhid**

They have said there may be invalid inputs. So what's the problem if there are negative values.

And I don't think two zeroes are valid because no triangle can be formed with the data. Anyway, This is just confusing.

Posted: **Sun Oct 26, 2003 2:00 pm**

by **Maarten**

the thing i hate about this problem is that one can interpret certain inputs in different ways. For example:

negative heights: this is either invalid, or one is supposed to use only absolute value of height. Both are equally probable.

2 zeros: It is possible to form a 'triangle' in which two heights are zero, although it's more like a line than.

A request to the problemsetter: please be more clear about what you mean. This kind of vagueness really takes away the pleasure of solving a problem.

Posted: **Sun Jun 27, 2004 5:47 am**

by **cytmike**

To all who feel confusing:

I got AC in the 4th time at last.

There should be no negative weights.

Also, if anyone of the heights is zero, it is invalid.

Hope this can help!

Posted: **Tue Mar 01, 2005 6:41 pm**

by **Sedefcho**

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.

Posted: **Thu Feb 23, 2006 9:17 am**

by **sclo**

The idea is this: use the relationship between area, height, and side lengths. Then apply Heron's formula. The condition to check for is that all 3 heights must be positive, and the expression inside the square root is also positive.

Posted: **Tue Feb 28, 2006 11:44 am**

by **ThanhNhan**

Sedefcho wrote:

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 [/code]

I used your conditions and worked out the formula:

Let A = the triangle area

We have : A = 1/2 ha * a = 1/2 hb * b = 1/2 hc * c (*)

In Heron's A = 1/4 sqtr( (a + b + c) *(-a + b + c) *(a - b + c) *(a + b - c) )

Let

x = 1/ha + 1/hb + 1/hc

y = -1/ha + 1/hb + 1/hc

z = 1/ha - 1/hb + 1/hc

t = 1/ha + 1/hb - 1/hc

Substitute a, b, c from (*) and simplify

A^2 = A^4 * x * y * z * t

<==> A = sqrt(1 / (x * y * z * t) )

However, I could not get Accepted because of some precision errors.

Does anyone have any suggestion of how to express the answer ?

### 10522---repeatedly getting WA! Plz HELP!!!!!!!!!!!!

Posted: **Sat Oct 07, 2006 8:24 pm**

by **dust_cover**

Can someone tell me why am I getting WA?

Though I have added all the conditions discusse before....but getting WA!

Code: Select all

```
#include<stdio.h>
#include<math.h>
int main(void)
{
int invalid, counter=0;
long double A, B, C;
long double HA, HB, HC;
long double a, b, c, d;
long double x, area;
//freopen("10522.txt","r", stdin);
//freopen("10522.out","w", stdout);
scanf("%d", & invalid);
while(1)
{
scanf("%Lf%Lf%Lf",&HA,&HB,&HC);
if(HA < 0 || HB <0 || HC < 0)
{
counter++;
printf("These are invalid inputs!\n");
if(counter==invalid)
break;
}
A = 1/HA;
B = 1/HB;
C = 1/HC;
a = (A+B+C);
b = (-A+B+C);
c = (A-B+C);
d = (A+B-C);
if( a<0 || b<0 || c<0 )
{
counter++;
printf("These are invalid inputs!\n");
if(counter==invalid)
break;
}
else
{
//x = 1/(a*b*c*d) ;
//area = sqrt(x);
printf("%.3Lf\n", sqrt( 1/(a*b*c*d)));
}
}
return 0;
}
```

thnx in advance!

Posted: **Mon Oct 09, 2006 11:50 pm**

by **sakhassan**

Post in an existing thread if possible;

If there isn't one, create one with the problem number and title in the subject line;

Posted: **Mon Feb 05, 2007 12:01 am**

by **jurajz**

ThanhNhan wrote:
I used your conditions and worked out the formula:

Let A = the triangle area

We have : A = 1/2 ha * a = 1/2 hb * b = 1/2 hc * c (*)

In Heron's A = 1/4 sqtr( (a + b + c) *(-a + b + c) *(a - b + c) *(a + b - c) )

Let

x = 1/ha + 1/hb + 1/hc

y = -1/ha + 1/hb + 1/hc

z = 1/ha - 1/hb + 1/hc

t = 1/ha + 1/hb - 1/hc

Substitute a, b, c from (*) and simplify

A^2 = A^4 * x * y * z * t

<==> A = sqrt(1 / (x * y * z * t) )

However, I could not get Accepted because of some precision errors.

Does anyone have any suggestion of how to express the answer ?

I have solved problem with help of this formula. I have one suggestion: I solved it with Pascal, variables ha, hb, hc, x, y, z, t and s (area) were of type extended. So, you can try it in the same way, or you can try use double/long double in C/C++.

Please, sorry for my bad english.

Posted: **Sun Apr 01, 2007 4:13 pm**

by **randomtea**

Maarten wrote:did you consider the case where either one of a,b,c is equal to zero?

thanks for your remind.

it seems that i fogot this constraint and only checking if 1/Ha+1/Hb>1/Hc

### This simple code gives WA .Plzzzzz somebody help me

Posted: **Sun Sep 28, 2008 5:29 am**

by **sujon**

Code: Select all

```
#include<iostream.h>
#include<stdio.h>
#include<math.h>
//#include<conio.h>
int main()
{
//clrscr();
long double ha,hb,hc,A,B,C,S,ar,a,b,c,d;
int invalid;
freopen("input.txt","r",stdin);
cin>>invalid;
int count=0;
while(count<invalid)
{
cin>>ha>>hb>>hc;
if(ha<=0.0||hb<=0.0||hc<=0.0)
{
printf("These are invalid inputs!\n");
count++;
//if(count==invalid)
//break;
}
A=(long double)1/ha;
B=(long double)1/hb;
C=(long double)1/hc;
a=A+B+C;
b=-A+B+C;
c=A-B+C;
d=A+B-C;
if(a<=0||b<=0||c<=0||d<=0)
{
printf("These are invalid inputs!\n");
count++;
}
else
{
ar=(long double)1/sqrt((double)(a*b*c*d));
printf("%.3Lf\n",ar);
}
}
return 0;
}
```

### Re: 10522 - Height to Area

Posted: **Tue Feb 24, 2015 10:09 pm**

by **tusher.ahamed**

I am repeatedly getting wrong answer on this code. can someone tell me what is wrong with my code ??

Code: Select all

```
#include <iostream>
#include <cmath>
#include <cstdio>
using namespace std;
int main()
{
double area,ha,hb,hc,t;
cin>>t;
while(cin>>ha>>hb>>hc)
{
area=((ha*hb*hc)*(ha*hb*hc))/sqrt((hb*hc+ha*hc+ha*hb)*(-hb*hc+ha*hc+ha*hb)*(hb*hc-ha*hc+ha*hb)*(hb*hc+ha*hc-ha*hb));
if(!isnan(area))
{
printf("%.3lf\n",area);
}
else { cout<<"These are invalid inputs!"<<endl;
t--;
if(t==0) break;}
}
return 0;
}
```