Page 2 of 3
Posted: Wed Jun 20, 2007 6:43 pm
by ayeshapakhi
thanks a lot its.. working now!!
Posted: Wed Jun 20, 2007 7:57 pm
by pradeepr
thanks it working now..
Posted: Sun Jul 29, 2007 3:05 pm
by newton
just change the condition
to:
and also use Long double
check spelling b4 submit....
hope that help
Posted: Tue Aug 07, 2007 12:39 pm
by jainal cse du
Getting WA.Needs help pls..
Code: Select all
#include <stdio.h>
#include <math.h>
int main()
{
double a,b,c,temp,area,s;
while(scanf("%lf %lf %lf",&a,&b,&c) == 3)
{
s = (a + b + c) / 2.0;
temp = sqrt(s * (s - a) * (s - b) * (s - b));
area = (temp * 4.0 ) / 3.0;
if(area <= 0)
area = -1.000;
printf("%.3lf\n",area + 1e-7);
}
return 0;
}
Posted: Tue Aug 07, 2007 8:01 pm
by Jan
I believe you have misunderstood the problem. Check the cases.
Input:
Code: Select all
35 68 42
25 70 1
63 59 79
46 6 65
62 28 82
43 96 92
92 37 28
54 3 5
22 83 93
96 19 17
72 27 48
Output:
Code: Select all
814.478
-1.000
2445.010
-1.000
922.651
2611.860
-1.000
-1.000
1140.610
-1.000
482.086
Hope these help.
at least 20 times WA 10347 - Medians .pls help
Posted: Sat Sep 27, 2008 9:48 am
by calicratis19
Re: 10347 - Medians
Posted: Tue Jun 30, 2009 12:49 pm
by asif_khan_ak_07
i got a formula on the internet which helps to calculate the area of the triangle using three median. it is
1/3(sqrt(2(u^2v^2+u^2w^2+v^2w^2)-(u^4+v^4+w^4))
where u,v,w are the median of the triangle. using this i wrote the program...i got correct results for several test cases posted in this forum but the online judge result is WA.

can u plz find my mistake
Code: Select all
#include<stdio.h>
#include<math.h>
int main()
{
//freopen("tri.txt","r",stdin);
long double a[3];
long double t,p,r,s,u,v,temp,ans;
while((scanf("%Lf %Lf %Lf",&a[0],&a[1],&a[2])==3))
{
t=pow(a[0],2);
p=pow(a[1],2);
r=pow(a[2],2);
s=pow(a[0],4);
u=pow(a[1],4);
v=pow(a[2],4);
temp=2*((t*p)+(t*r)+(p*r))-(s+u+v);
temp=sqrt(temp);
ans=temp/3;
if(ans>0)
printf("%.3Lf\n",ans);
else
printf("-1.000\n");
}
return 0;
}
Re: 10347 - Medians
Posted: Tue Jun 30, 2009 1:06 pm
by Obaida
change your long double to double..
and remove your code after acc...

Re: 10347 - Medians
Posted: Wed Jul 01, 2009 7:08 am
by asif_khan_ak_07
i got AC thkns.....but what was the problem with long double??
Re: 10347 - Medians
Posted: Fri Sep 24, 2010 8:32 pm
by Martuza_iu
pls help me i got WA.
Code: Select all
#include<stdio.h>
#include<math.h>
int main()
{
double area,m1,m2,m3,l,s,p;
while(scanf("%lf%lf%lf",&m1,&m2,&m3)!=EOF)
{
s=(m1+m2+m3)/2;
l=s*(s-m1)*(s-m2)*(s-m3);
p=sqrt(l);
area=(4*p)/3;
if(m1==0||m2==0||m3==0||area<=0)
printf("-1.000\n");
else
printf("%.3lf\n",area);
}
return 0;
}
Re: 10347 - Medians
Posted: Thu Jun 23, 2011 4:26 pm
by plamplam
You must print -1.000 and not -1. Im sure most of you used this formula area = (1 / 3.0) * sqrt(z), where z is some pre-calculated number which you calculated somehow

(I aint giving away the solution

). Now if z < 0 then obviously you are printing -1.000. Don't do this, change you code to if z <= 0 then printf("-1.000\n"); This is because when the area is 0 you have to state that it is impossible

. Note that in some previous threads many claimed that long double doesn't work and complained about precision error. Don't be confused. I tested my code without adding eps and I also tried with long double. Both of them got AC. So if you're getting Wrong Answer and your code passes Jan's sample I/O, then its most probably because your code is not printing -1.000 when the area is 0.
Re: 10347 - Medians
Posted: Sat Mar 31, 2012 11:06 pm
by atiburrahman09
Can not Find any problem in my code.Can someone please say what is the problem???
#include<iostream>
#include<stdio.h>
using namespace std;
#include<cmath>
#include<iomanip>
#include<cstdio>
int main(){
int med1,med2,med3;
double area,s,a,b,c;
while(scanf("%d %d %d",&med1,&med2,&med3)!=EOF)
{
a=sqrt(-(med1*med1)+2*(med2*med2)+2*(med3*med3))*2/3;
b=sqrt(-(med2*med2)+2*(med1*med1)+2*(med3*med3))*2/3;
c=sqrt(-(med3*med3)+2*(med2*med2)+2*(med1*med1))*2/3;
if((a+b)>c && (a+c)>b && (b+c)>a)
{
s=(a+b+c)/2;
area=sqrt(s*(s-a)*(s-b)*(s-c));
}
else
area=-1.000;
if(area>=0)
printf("%.3lf\n",area);
else
printf("-1.000");
}
return 0;
}
10347-WHY TLE???
Posted: Sun Apr 01, 2012 12:20 am
by atiburrahman09
Can not Find any problem in my code.Can someone please say what is the problem???
#include<iostream>
#include<stdio.h>
using namespace std;
#include<cmath>
#include<iomanip>
#include<cstdio>
int main(){
int med1,med2,med3;
double area,s,a,b,c;
while(scanf("%d %d %d",&med1,&med2,&med3)!=EOF)
{
a=sqrt(-(med1*med1)+2*(med2*med2)+2*(med3*med3))*2/3;
b=sqrt(-(med2*med2)+2*(med1*med1)+2*(med3*med3))*2/3;
c=sqrt(-(med3*med3)+2*(med2*med2)+2*(med1*med1))*2/3;
if((a+b)>c && (a+c)>b && (b+c)>a)
{
s=(a+b+c)/2;
area=sqrt(s*(s-a)*(s-b)*(s-c));
}
else
area=-1.000;
if(area>=0)
printf("%.3lf\n",area);
else
printf("-1.000");
}
return 0;
}
atiburrahman09
New poster
Posts: 2
Joined: Tue Mar 27, 2012 3:12 am
Re: 10347-WHY TLE???
Posted: Mon Apr 02, 2012 10:10 pm
by brianfry713
Do this instead:
while(scanf("%d%d%d",&med1,&med2,&med3)==3)
and you will get WA in 0.008 seconds.
Re: 10347 - Medians
Posted: Mon Apr 02, 2012 10:11 pm
by brianfry713
Do this instead:
while(scanf("%d%d%d",&med1,&med2,&med3)==3)
and you will get WA in 0.008 seconds.