## 10347 - Medians

Moderator: Board moderators

hello...

change....
Code: Select all
`cout<<"-1"<<'\n'; `

to
Code: Select all
`cout<<"-1.000"<<'\n'; `
ayeshapakhi
Learning poster

Posts: 60
Joined: Sun Apr 16, 2006 7:59 pm

### thanks a lot its.. working now!!

thanks it working now..
New poster

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

just change the condition

Code: Select all
`if(a<0||b<0||c<0)`

to:
Code: Select all
`if(area <= 0)`

and also use Long double
check spelling b4 submit....

hope that help

newton
Experienced poster

Posts: 162
Joined: Thu Jul 13, 2006 7:07 am

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;}`

jainal cse du
New poster

Posts: 23
Joined: Thu Jul 27, 2006 2:43 pm

I believe you have misunderstood the problem. Check the cases.

Input:
Code: Select all
`35 68 4225 70 163 59 7946 6 6562 28 8243 96 9292 37 2854 3 522 83 9396 19 1772 27 48`

Output:
Code: Select all
`814.478-1.0002445.010-1.000922.6512611.860-1.000-1.0001140.610-1.000482.086`

Hope these help.
Ami ekhono shopno dekhi...
HomePage
Jan
Guru

Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm

### at least 20 times WA 10347 - Medians .pls help

AC.

to hell with precision error.
Heal The World
calicratis19
Learning poster

Posts: 76
Joined: Mon Jul 21, 2008 8:50 am

### Re: 10347 - Medians

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;}`
asif_khan_ak_07
New poster

Posts: 25
Joined: Fri Apr 17, 2009 8:24 am

### Re: 10347 - Medians

change your long double to double..
and remove your code after acc...
try_try_try_try_&&&_try@try.com
This may be the address of success.
Obaida
A great helper

Posts: 380
Joined: Wed Jan 16, 2008 6:51 am

### Re: 10347 - Medians

i got AC thkns.....but what was the problem with long double??
asif_khan_ak_07
New poster

Posts: 25
Joined: Fri Apr 17, 2009 8:24 am

### Re: 10347 - Medians

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");elseprintf("%.3lf\n",area);   }   return 0;}`
Martuza_iu
New poster

Posts: 4
Joined: Tue Sep 21, 2010 4:17 pm
Location: Islamic University, Kushtia

### Re: 10347 - Medians

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.
You tried your best and you failed miserably. The lesson is 'never try'. -Homer Simpson

plamplam
Experienced poster

Posts: 151
Joined: Fri May 06, 2011 11:37 am

### Re: 10347 - Medians

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: 6
Joined: Mon Mar 26, 2012 10:12 pm

### Re: 10347 - Medians

while(scanf("%d%d%d",&med1,&med2,&med3)==3)

and you will get WA in 0.008 seconds.
brianfry713
Guru

Posts: 1870
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Previous