10522 - Height to Area
Moderator: Board moderators
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 ?
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
ya...i am wondering whether area=o is valid or not.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 ?
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....
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.
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.
Given three real numbers ( double, long double numbers
in terms of C++ ) Ha, Hb, Hc we can state the following :
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.
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
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 used your conditions and worked out the formula: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]
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 ?
-
- New poster
- Posts: 23
- Joined: Tue Sep 12, 2006 9:46 pm
10522---repeatedly getting WA! Plz HELP!!!!!!!!!!!!
Can someone tell me why am I getting WA?
Though I have added all the conditions discusse before....but getting WA!
thnx in advance! 
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;
}

i wanna give it a try....
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++.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 ?
Please, sorry for my bad english.
This simple code gives WA .Plzzzzz somebody help me
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;
}
-
- New poster
- Posts: 2
- Joined: Wed Feb 11, 2015 4:45 pm
Re: 10522 - Height to Area
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;
}