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

Maarten
Experienced poster
Posts: 108
Joined: Sat Sep 27, 2003 5:24 pm

Post by Maarten » Thu Oct 23, 2003 10:41 am

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 ?

nonstop
New poster
Posts: 14
Joined: Fri Oct 03, 2003 5:13 am

ya

Post by nonstop » Fri Oct 24, 2003 10:44 am

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....

Maarten
Experienced poster
Posts: 108
Joined: Sat Sep 27, 2003 5:24 pm

Post by Maarten » Fri Oct 24, 2003 10:53 am

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]

Towhid
New poster
Posts: 38
Joined: Wed May 28, 2003 5:30 pm
Location: Bangladesh
Contact:

Post by Towhid » Sat Oct 25, 2003 2:32 pm

They have said there may be invalid inputs. So what's the problem if there are negative values. :roll: And I don't think two zeroes are valid because no triangle can be formed with the data. Anyway, This is just confusing.
From 0 to 0

Maarten
Experienced poster
Posts: 108
Joined: Sat Sep 27, 2003 5:24 pm

Post by Maarten » Sun Oct 26, 2003 2:00 pm

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.

User avatar
cytmike
Learning poster
Posts: 95
Joined: Mon Apr 26, 2004 1:23 pm
Location: Hong Kong and United States
Contact:

Post by cytmike » Sun Jun 27, 2004 5:47 am

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! :D

User avatar
Sedefcho
A great helper
Posts: 374
Joined: Sun Jan 16, 2005 10:18 pm
Location: Bulgaria

Post by Sedefcho » 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.

sclo
Guru
Posts: 519
Joined: Mon Jan 23, 2006 10:45 pm
Location: Vancouver, BC, Canada
Contact:

Post by sclo » Thu Feb 23, 2006 9:17 am

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.

ThanhNhan
New poster
Posts: 15
Joined: Sun Aug 08, 2004 12:24 am

Post by ThanhNhan » Tue Feb 28, 2006 11:44 am

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 ?

User avatar
dust_cover
New poster
Posts: 23
Joined: Tue Sep 12, 2006 9:46 pm

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

Post by dust_cover » Sat Oct 07, 2006 8:24 pm

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! :D
i wanna give it a try....

sakhassan
Experienced poster
Posts: 105
Joined: Sat Mar 11, 2006 9:42 am
Location: cse,DU

Post by sakhassan » Mon Oct 09, 2006 11:50 pm

Post in an existing thread if possible;


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

jurajz
Learning poster
Posts: 69
Joined: Sat Sep 02, 2006 7:30 pm
Location: Slovakia

Post by jurajz » Mon Feb 05, 2007 12:01 am

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.

randomtea
New poster
Posts: 5
Joined: Sun Apr 01, 2007 3:48 pm

Post by randomtea » Sun Apr 01, 2007 4:13 pm

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

sujon
New poster
Posts: 5
Joined: Thu Aug 28, 2008 4:17 pm

This simple code gives WA .Plzzzzz somebody help me

Post by sujon » Sun Sep 28, 2008 5:29 am

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;
}



tusher.ahamed
New poster
Posts: 2
Joined: Wed Feb 11, 2015 4:45 pm

Re: 10522 - Height to Area

Post by tusher.ahamed » Tue Feb 24, 2015 10:09 pm

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;
}


Post Reply

Return to “Volume 105 (10500-10599)”