10347  Medians
Moderator: Board moderators
10347  Medians
I have no idea why my code gets WA
I know this simple formulas:
S=(4/3)*(m(mma)(mmb)(mmc))^(1/2) , where m=(ma+mb+mc)/2;
a=(2/3)*(2mb^2+2mc^2ma^2)^(1/2);
Am I wrong?
But my program is wrong
[pascal]Program p10347;
Const Eps = 1e10;
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*m2m3*m3>Eps then a:=2/3*sqrt(Abs(2*m1*m1+2*m2*m2m3*m3)) else a:=1;
if 2*m2*m2+2*m3*m3m1*m1>Eps then b:=2/3*sqrt(Abs(2*m2*m2+2*m3*m3m1*m1)) else b:=1;
if 2*m3*m3+2*m1*m1m2*m2>Eps then c:=2/3*sqrt(Abs(2*m3*m3+2*m1*m1m2*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*(mm1)*(mm2)*(mm3)):0:3);
end;
end.[/pascal]
I know this simple formulas:
S=(4/3)*(m(mma)(mmb)(mmc))^(1/2) , where m=(ma+mb+mc)/2;
a=(2/3)*(2mb^2+2mc^2ma^2)^(1/2);
Am I wrong?
But my program is wrong
[pascal]Program p10347;
Const Eps = 1e10;
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*m2m3*m3>Eps then a:=2/3*sqrt(Abs(2*m1*m1+2*m2*m2m3*m3)) else a:=1;
if 2*m2*m2+2*m3*m3m1*m1>Eps then b:=2/3*sqrt(Abs(2*m2*m2+2*m3*m3m1*m1)) else b:=1;
if 2*m3*m3+2*m1*m1m2*m2>Eps then c:=2/3*sqrt(Abs(2*m3*m3+2*m1*m1m2*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*(mm1)*(mm2)*(mm3)):0:3);
end;
end.[/pascal]

 Guru
 Posts: 724
 Joined: Wed Dec 19, 2001 2:00 am
 Location: Germany
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+mcma)*(ma+mcmb)*(ma+mbmc))/3.0.
I think my values should be precise enough, I used:
area = sqrt((ma+mb+mc)*(mb+mcma)*(ma+mcmb)*(ma+mbmc))/3.0.

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

 Guru
 Posts: 724
 Joined: Wed Dec 19, 2001 2:00 am
 Location: Germany
Always WA!!!
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!!!
[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*b2*c*c)/2;
if (aux <= 0) return 1;
z=sqrt (aux);
y=(b*ba*a)/(4*z);
aux=c*cy*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]
Heeelppp!!!
[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*b2*c*c)/2;
if (aux <= 0) return 1;
z=sqrt (aux);
y=(b*ba*a)/(4*z);
aux=c*cy*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]

 Guru
 Posts: 834
 Joined: Wed May 29, 2002 4:11 pm
 Location: Wroclaw, Poland
 Contact:
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 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)
Born from ashes  restarting counter of problems (800+ solved problems)
 CodeMaker
 Experienced poster
 Posts: 183
 Joined: Thu Nov 11, 2004 12:35 pm
 Location: AIUB, Bangladesh
10347
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*(sx)*(sy)*(sz);
if(v<=0)
{
printf("1.000\n");
continue;
}
s=sqrt(v);
s*=(4.0/3.0);
printf("%.3lf\n",s);
}
}
Jalal : AIUB SPARKS
Re: Why output limit exceeded in 10347(median)
after the last number you should expect some whitespace and so probably scanf never returns EOF.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) /* ... */
Code: Select all
while(scanf("%d%d%d",&x,&y,&z)==3)
Ciao!!!
Claudio
 ibrahim
 Experienced poster
 Posts: 149
 Joined: Mon Feb 07, 2005 10:28 pm
 Location: Northern University, Bangladesh
 Contact:
10347 Need I/0
I got WA with my code. Can you please help me by giveing critical I/O.
I really need this.
I really need this.

 New poster
 Posts: 4
 Joined: Sat Apr 02, 2005 3:10 pm
 Location: Bangladesh
10347 Medians WA!
I got WA for several times Can any body fix my error?
Thanking u for help.
I've got AC just now!
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!
3.If area is even 0 print 1.
4. And always print 1 as 1.000
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*(sa)*(sb)*(sc);
if(a<0b<0c<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*/
}
I've got AC just now!
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!
3.If area is even 0 print 1.
4. And always print 1 as 1.000
WA... somebody plz help me out!!
this is my code.. but it gives me a wrong ans..
[code]
[/code]
[code]
[/code]
Last edited by pradeepr on Wed Jun 20, 2007 8:00 pm, edited 2 times in total.