10320 - Cow Trouble! Help Please!!

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 Picard » Fri Jul 05, 2002 8:37 pm

are you sure it's not just a compile error because of redefining M_PI (if you include math.h).
this is a good solution and it's very much a spoiler
Picard
Learning poster
 
Posts: 96
Joined: Mon Jun 24, 2002 1:22 pm
Location: Hungary

Postby Joe Smith » Sat Jul 06, 2002 3:00 am

Picard wrote:are you sure it's not just a compile error because of redefining M_PI (if you include math.h).
this is a good solution and it's very much a spoiler


This is strange -- I get AC now.

The only thing I remember changing from my most recent WA was I factored out a M_PI... but maybe that did it. Or maybe there was some bad data they changed. (I hate floating point.)

The reason I redefined M_PI (it's only a warning, not a compile error) is because I seem to remember that it wasn't defined in math.h on UVA. I may be wrong on that, but I know hypot isn't defined.
Joe Smith
New poster
 
Posts: 26
Joined: Wed Apr 17, 2002 5:56 am

10320 cow trouble

Postby Subeen » Tue Sep 10, 2002 7:45 am

my code gets WA. :oops: but i think the problem is simple and easy to solve. i find the area of 3/4 of the circle using the formula pi*R*R, and rest of the area using similar formula.
someone plz find what wrong with my code or the approach is wrong
[c]
#include <stdio.h>
#include <math.h>

#define pi 2*acos(0)

void main()
{
double l, w, R, area, area1, area2, area3;
while(3==scanf("%lf%lf%lf", &l, &w, &R))
{
area2 = area3 = 0;
area1 = 3 * pi * R * R / 4;
if(R >= l)
area2 = pi * (R - l) * (R - l) / 4;
if(R >= w)
area3 = pi * (R - w) * (R - w) / 4;
area = area1 + area2 + area3;
printf("%0.10lf\n", area);
}
}
[/c]
thanx...
Last edited by Subeen on Wed Sep 11, 2002 7:28 am, edited 1 time in total.
Subeen
Experienced poster
 
Posts: 127
Joined: Tue Nov 06, 2001 2:00 am
Location: Bangladesh

Postby Dominik Michniewski » Tue Sep 10, 2002 8:16 am

Are yot sure that
Code: Select all
printf("%0.10lf" ....

is similar to
Code: Select all
printf("%.10lf" ....

I think (maybe wrong) that 0.10 prints in some systems something like 0001.00000000 - maybe it's your problem ?

I don't try to solve this question yet and I can't say any word about your algorithm :-(

Best greetings
Dominik Michniewski
Guru
 
Posts: 828
Joined: Wed May 29, 2002 4:11 pm
Location: Wroclaw, Poland

Moo!

Postby Yarin » Tue Sep 10, 2002 1:38 pm

Your solution only works when R<=l+w. This is the easy case, it gets a lot more complicated when R >l+w. Sadly the sample input doesn't have such an input case...

Try the input

7 3 9
9 5 2
18 2 7

The correct answer should be

222.2676802415
9.4247779608
135.0884841044
Yarin
Problemsetter
 
Posts: 112
Joined: Tue Sep 10, 2002 5:06 am
Location: Ume

Postby Subeen » Wed Sep 11, 2002 7:31 am

Yarin, I don't understand what do u mean by
Your solution only works when R<=l+w. This is the easy case, it gets a lot more complicated when R >l+w.


after some modification ( area2 = area3 = 0) my program gives the same output as your's.

but still getting WA... :(
Subeen
Experienced poster
 
Posts: 127
Joined: Tue Nov 06, 2001 2:00 am
Location: Bangladesh

Postby Yarin » Wed Sep 11, 2002 11:37 am

I'm terribly sorry, I had the parameters the wrong way. The input should be

3 9 7
5 2 9
2 7 18

and the correct answer

128.0199006338
238.3325404965
992.2996351671

which your program does not output.
Yarin
Problemsetter
 
Posts: 112
Joined: Tue Sep 10, 2002 5:06 am
Location: Ume

how is that?

Postby choyon_buet » Wed Mar 05, 2003 12:18 am

Thanks to yarin cause i could realize my mistake with my calculation from the sample I/O given by u.And i got this problem accepted at last :D .

but i am so astonished to see that my output doesn't match with yours completely.it differs in the 9th and10th points after the decimal.


suppose for the
input : 5 2 9
my code gives the output: 238.3325404991

so here the last two digits are 91 when ur output is 65.

but both of us got accepted.
CAN U TELL ME HOW IS THAT POSSIBLE? :o
choyon_buet
New poster
 
Posts: 5
Joined: Mon Feb 24, 2003 5:28 pm
Location: BANGLADESH

Postby saiqbal » Mon Mar 10, 2003 9:44 pm

its possible bcoz its an special judge problem.
an special corrector program is written for this problem to ignore small precision error. :)
User avatar
saiqbal
New poster
 
Posts: 36
Joined: Wed Aug 07, 2002 4:52 pm
Location: Dhaka, Bangladesh

10320(Needed formula)

Postby hridoy » Tue Dec 18, 2007 10:03 pm

Can anyone plz tell me How can I evaluate the formula when R>(l+w)??
hridoy
New poster
 
Posts: 21
Joined: Tue May 08, 2007 10:30 am
Location: Dhaka

Postby CMG » Wed Dec 19, 2007 8:07 am

im not exactly sure myself at the moment, but from observation I found a good approximation for when R>(l+w):

A = (pi*3*R^2)/4 + (pi*(R - l)^2)/4 + (pi*(R - w)^2)/4 - (pi*(R - l - w)^2)/4
= pi*(R^2 - l*w/2)

which gives 238.76104 for the 5 2 9 case above.

If I come up with anything better Ill post it.
User avatar
CMG
New poster
 
Posts: 37
Joined: Sat Dec 08, 2007 5:01 am
Location: ...

Re: 10320 - Cow Trouble! Help Please!!

Postby Sh0rty » Mon Nov 17, 2008 9:21 pm

PLs can somebody help me?I have problem like others when R > W+L.I still don`t know resolution for this case.It`s very important for me - Thank you very much.
Sh0rty
New poster
 
Posts: 1
Joined: Mon Nov 17, 2008 3:02 pm

Re: 10320 - Cow Trouble! Help Please!!

Postby DD » Sun Apr 17, 2011 10:35 pm

The most tricky case happens when R > l + w. You need to solve some equations first to get the final answer. 8)
Sh0rty wrote:PLs can somebody help me?I have problem like others when R > W+L.I still don`t know resolution for this case.It`s very important for me - Thank you very much.
Have you ever...

    Wanted to work at best companies?
    Struggled with interview problems that could be solved in 15 minutes?
    Wished you could study real-world problems?
If so, you need to read Elements of Programming Interviews.
DD
Experienced poster
 
Posts: 145
Joined: Thu Aug 14, 2003 8:42 am
Location: Mountain View, California

Previous

Return to Volume CIII

Who is online

Users browsing this forum: No registered users and 1 guest

cron