10347 - Medians

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

Moderator: Board moderators

Postby ayeshapakhi » Wed Jun 20, 2007 6:43 pm

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!!

Postby pradeepr » Wed Jun 20, 2007 7:57 pm

thanks it working now..
pradeepr
New poster
 
Posts: 21
Joined: Fri May 25, 2007 11:52 am
Location: India

Postby newton » Sun Jul 29, 2007 3:05 pm

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
User avatar
newton
Experienced poster
 
Posts: 162
Joined: Thu Jul 13, 2006 7:07 am
Location: Campus Area. Dhaka.Bangladesh

Postby jainal cse du » Tue Aug 07, 2007 12:39 pm

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

User avatar
jainal cse du
New poster
 
Posts: 23
Joined: Thu Jul 27, 2006 2:43 pm
Location: University of Dhaka,Bangladesh

Postby Jan » Tue Aug 07, 2007 8:01 pm

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.
Ami ekhono shopno dekhi...
HomePage
Jan
Guru
 
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh

at least 20 times WA 10347 - Medians .pls help

Postby calicratis19 » Sat Sep 27, 2008 9:48 am

AC. :lol: :lol: :lol: :lol:

to hell with precision error. :evil: :evil: :evil: :evil: :evil:
Heal The World
calicratis19
Learning poster
 
Posts: 76
Joined: Mon Jul 21, 2008 8:50 am
Location: SUST,SYLHET,BANGLADESH.

Re: 10347 - Medians

Postby asif_khan_ak_07 » Tue Jun 30, 2009 12:49 pm

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

Postby Obaida » Tue Jun 30, 2009 1:06 pm

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
Location: (BUBT) Dhaka,Bagladesh.

Re: 10347 - Medians

Postby asif_khan_ak_07 » Wed Jul 01, 2009 7:08 am

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

Postby Martuza_iu » Fri Sep 24, 2010 8:32 pm

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;
}
Martuza_iu
New poster
 
Posts: 4
Joined: Tue Sep 21, 2010 4:17 pm
Location: Islamic University, Kushtia

Re: 10347 - Medians

Postby plamplam » Thu Jun 23, 2011 4:26 pm

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 :D (I aint giving away the solution :P ). 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 :D . 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
User avatar
plamplam
Experienced poster
 
Posts: 151
Joined: Fri May 06, 2011 11:37 am

Re: 10347 - Medians

Postby atiburrahman09 » Sat Mar 31, 2012 11:06 pm

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

Postby brianfry713 » Mon Apr 02, 2012 10:11 pm

Do this instead:
while(scanf("%d%d%d",&med1,&med2,&med3)==3)

and you will get WA in 0.008 seconds.
brianfry713
Guru
 
Posts: 1864
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Previous

Return to Volume CIII

Who is online

Users browsing this forum: No registered users and 0 guests