10347 - Medians

All about problems in Volume 103. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

Revenger
Experienced poster
Posts: 132
Joined: Sun Apr 14, 2002 12:27 pm
Location: Russia

10347 - Medians

Post by Revenger » Wed Aug 28, 2002 3:38 pm

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]

Adrian Kuegel
Guru
Posts: 724
Joined: Wed Dec 19, 2001 2:00 am
Location: Germany

Post by Adrian Kuegel » Wed Aug 28, 2002 8:31 pm

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.

ithamar
Learning poster
Posts: 56
Joined: Mon May 13, 2002 11:58 pm
Location: Venezuela

Post by ithamar » Thu Aug 29, 2002 5:54 am

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.

AlexandreN
New poster
Posts: 27
Joined: Sun Jul 07, 2002 6:46 pm
Location: Campina Grande - Brazil
Contact:

Post by AlexandreN » Thu Aug 29, 2002 5:14 pm

to Adrian K

Adrian Kuegel
Guru
Posts: 724
Joined: Wed Dec 19, 2001 2:00 am
Location: Germany

Post by Adrian Kuegel » Thu Aug 29, 2002 5:21 pm

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.

Cucu
New poster
Posts: 4
Joined: Wed Nov 20, 2002 9:43 pm

Always WA!!!

Post by Cucu » Wed Nov 20, 2002 9:48 pm

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]

Larry
Guru
Posts: 647
Joined: Wed Jun 26, 2002 10:12 pm
Location: Hong Kong and New York City
Contact:

Post by Larry » Thu Nov 21, 2002 7:53 am

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?

Dominik Michniewski
Guru
Posts: 834
Joined: Wed May 29, 2002 4:11 pm
Location: Wroclaw, Poland
Contact:

Post by Dominik Michniewski » Mon Jul 07, 2003 8:09 am

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
If you really want to get Accepted, try to think about possible, and after that - about impossible ... and you'll get, what you want ....
Born from ashes - restarting counter of problems (800+ solved problems)

User avatar
CodeMaker
Experienced poster
Posts: 183
Joined: Thu Nov 11, 2004 12:35 pm
Location: AIUB, Bangladesh

10347

Post by CodeMaker » Fri Jan 14, 2005 5:34 am

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);
	}
}
Jalal : AIUB SPARKS

CDiMa
Experienced poster
Posts: 214
Joined: Fri Oct 17, 2003 5:49 pm
Location: Genova

Re: Why output limit exceeded in 10347(median)

Post by CDiMa » Fri Jan 14, 2005 10:56 am

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

User avatar
ibrahim
Experienced poster
Posts: 149
Joined: Mon Feb 07, 2005 10:28 pm
Location: Northern University, Bangladesh
Contact:

10347 Need I/0

Post by ibrahim » Fri Feb 25, 2005 7:46 pm

I got WA with my code. Can you please help me by giveing critical I/O.
I really need this. :(

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

Post by Sedefcho » Fri Apr 01, 2005 1:14 am

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.

Fakhrul Abedin
New poster
Posts: 4
Joined: Sat Apr 02, 2005 3:10 pm
Location: Bangladesh

10347 Medians WA!

Post by Fakhrul Abedin » Mon Apr 04, 2005 4:08 pm

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

Darko
Guru
Posts: 580
Joined: Fri Nov 11, 2005 9:34 am
Location: Calgary, Canada

Post by Darko » Tue Feb 21, 2006 11:21 am

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

pradeepr
New poster
Posts: 21
Joined: Fri May 25, 2007 11:52 am
Location: India

WA... somebody plz help me out!!

Post by pradeepr » Wed Jun 20, 2007 6:03 pm

this is my code.. but it gives me a wrong ans..
[code]
[/code]
Last edited by pradeepr on Wed Jun 20, 2007 8:00 pm, edited 2 times in total.

Post Reply

Return to “Volume 103 (10300-10399)”