Page 1 of 3

10347 - Medians

Posted: Wed Aug 28, 2002 3:38 pm
by Revenger
I have no idea why my code gets WA

I know this simple formulas:

S=(4/3)*(m(m-ma)(m-mb)(m-mc))^(1/2) , where m=(ma+mb+mc)/2;

a=(2/3)*(2mb^2+2mc^2-ma^2)^(1/2);

Am I wrong?
But my program is wrong :cry:

[pascal]Program p10347;

Const Eps = 1e-10;

Var m1,m2,m3,m,a,b,c : Extended;

begin
While Not Eof do begin
Read(m1,m2,m3);
While Eoln do begin
if Eof then Break;
Readln;
end;
m:=(m1+m2+m3)/2;
if 2*m1*m1+2*m2*m2-m3*m3>-Eps then a:=2/3*sqrt(Abs(2*m1*m1+2*m2*m2-m3*m3)) else a:=-1;
if 2*m2*m2+2*m3*m3-m1*m1>-Eps then b:=2/3*sqrt(Abs(2*m2*m2+2*m3*m3-m1*m1)) else b:=-1;
if 2*m3*m3+2*m1*m1-m2*m2>-Eps then c:=2/3*sqrt(Abs(2*m3*m3+2*m1*m1-m2*m2)) else c:=-1;
if (a<-0.5) or (b<-0.5) or (c<-0.5) or
(m1<-Eps) or (m2<-Eps) or (m3<-Eps) or
(a+b<c) or (a+c<b) or (b+c<a) then
Writeln('-1')
else
Writeln(4/3*sqrt(m*(m-m1)*(m-m2)*(m-m3)):0:3);
end;
end.[/pascal]

Posted: Wed Aug 28, 2002 8:31 pm
by Adrian Kuegel
I would like to know if the values should be rounded up like it is said in the problem description (but if I do it I get for the sample input 5.197). And what should be printed if the triangle is not a valid one, -1 or -1.000?
I think my values should be precise enough, I used:
area = sqrt((ma+mb+mc)*(mb+mc-ma)*(ma+mc-mb)*(ma+mb-mc))/3.0.

Posted: Thu Aug 29, 2002 5:54 am
by ithamar
I dont know what's wrong with this problem. Only one person get accepted. This is not normal. Besides i resolve this problem in the last contest and i get accepted in the contest. I submmited the exact same code here and i get WA. :o .

Anybody knows what's happening ....

Help apreciated.

Posted: Thu Aug 29, 2002 5:14 pm
by AlexandreN
to Adrian K

Posted: Thu Aug 29, 2002 5:21 pm
by Adrian Kuegel
Thanks for your reply, a few moments ago I read what has changed after the contest. In the case the area is 0 one should output -1.000. I got it Accepted.

Always WA!!!

Posted: Wed Nov 20, 2002 9:48 pm
by Cucu
Hi, I think that the program gives the rigth answer but I get wrong answer, I've tried many times changing subtilities in the presentation, but i coudn't get it accepted.
Heeelppp!!!
:evil:

[c]
#include <stdio.h>
#include <math.h>


double area (double m1, double m2, double m3)
{
double a,b,c, aux,x, y, z;
a=m1*2.0/3.0;
b=m2*2.0/3.0;
c=m3/3.0;
aux=(a*a+b*b-2*c*c)/2;
if (aux <= 0) return -1;
z=sqrt (aux);
y=(b*b-a*a)/(4*z);
aux=c*c-y*y;
if (aux<=0) return -1;
x=sqrt (aux);
return x*z*3;
}

int main ()
{
char s [100], *pp;
float m1, m2, m3,a;
while (1) {
pp= fgets (s,1000,stdin);
if (pp==NULL) return 0;
if (strlen (s) < 4) return -1;
m1=m2=m3=-1;
sscanf (pp, "%f %f %f",&m1, &m2, &m3);
a=area (m1,m2,m3);
if (a < 0.0000000001) a=-1;
printf ("%.3lf\n",a);
}
return 0;
}
[/c]

Posted: Thu Nov 21, 2002 7:53 am
by Larry
Don't know if this will solve your problem, but when I used float, it seemed to be not precise enough, and when I switched to doubles, it got AC the first time around.. so try that?

Posted: Mon Jul 07, 2003 8:09 am
by Dominik Michniewski
pay attention to value of area....
If I correct remember - area must be strictly positive (not zero). and think, in which cases you must print -1 (if area doesn't exist). think too about how you should output -1 value ;-)

Best regards
DM

10347

Posted: Fri Jan 14, 2005 5:34 am
by CodeMaker
Hi, why I get output limit exceeded?

Code: Select all

#include<stdio.h>
#include<math.h>

void main()
{
	int x,y,z;
	double s,v;

	while(scanf("%d%d%d",&x,&y,&z)!=EOF)
	{
		if(x<=0 || y<=0 || z<=0)
		{
			printf("-1.000\n");
			continue;
		}

		s=(x+y+z)*0.5;
		v=s*(s-x)*(s-y)*(s-z);
		if(v<=0)
		{
			printf("-1.000\n");
			continue;
		}
		s=sqrt(v);
		s*=(4.0/3.0);
		printf("%.3lf\n",s);
	}
}

Re: Why output limit exceeded in 10347(median)

Posted: Fri Jan 14, 2005 10:56 am
by CDiMa
CodeMaker wrote:Hi, why I get output limit exceeded?

Code: Select all

#include<stdio.h>
#include<math.h>

void main()
{
	int x,y,z;
	double s,v;

	while(scanf("%d%d%d",&x,&y,&z)!=EOF)
/* ... */
after the last number you should expect some whitespace and so probably scanf never returns EOF.

Code: Select all

while(scanf("%d%d%d",&x,&y,&z)==3)
will probably fix it.

Ciao!!!

Claudio

10347 Need I/0

Posted: Fri Feb 25, 2005 7:46 pm
by ibrahim
I got WA with my code. Can you please help me by giveing critical I/O.
I really need this. :(

Posted: Fri Apr 01, 2005 1:14 am
by Sedefcho
1. How do you check if the three values/lengths for
the MEDIANS are valid
( the case in which you should calculate the area and print it ) ?

2. If the three values given are not valid how do you print -1 ?
You should print it is -1.000.

I think one of these two is your problem.

10347 Medians WA!

Posted: Mon Apr 04, 2005 4:08 pm
by Fakhrul Abedin
I got WA for several times :cry: Can any body fix my error?

Code: Select all

#include<math.h>
#include<stdio.h>

main(){
	double a,b,c,s;
	double area,ara;
	while(scanf("%f%f%f",&a,&b,&c)!=EOF){
		
		s=(a+b+c)/2.0;		
		ara=s*(s-a)*(s-b)*(s-c);

		if(a<0||b<0||c<0)        area=-1.0;
		else if(ara<=0)		area=-1.0;
		else{
			area=sqrt(ara);
			area=4.0*area/3.0;
		}
		printf("%.3lf\n",area);
	}/*Input while end*/
}
Thanking u for help.

I've got AC just now! :D
What I do are following:
1. First I take a,b,c,s as float later I take double.
2. but I use "%f" instead of "%lf", so be carefull for such silly mistake! :o
3.If area is even 0 print -1.
4. And always print -1 as -1.000

Posted: Tue Feb 21, 2006 11:21 am
by Darko
This one is just plain silly - avoid integer arithmetic! Sigh... I should learn how to read...

Yes, use doubles for everything. (worked for Java too)

Darko

WA... somebody plz help me out!!

Posted: Wed Jun 20, 2007 6:03 pm
by pradeepr
this is my code.. but it gives me a wrong ans..
[code]
[/code]