10320 - Cow Trouble! Help Please!!

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

Moderator: Board moderators

Picard
Learning poster
Posts: 96
Joined: Mon Jun 24, 2002 1:22 pm
Location: Hungary
Contact:

Post by Picard »

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
Joe Smith
New poster
Posts: 26
Joined: Wed Apr 17, 2002 5:56 am

Post by Joe Smith »

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.
Subeen
Experienced poster
Posts: 127
Joined: Tue Nov 06, 2001 2:00 am
Location: Bangladesh
Contact:

10320 cow trouble

Post by Subeen »

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.
Dominik Michniewski
Guru
Posts: 834
Joined: Wed May 29, 2002 4:11 pm
Location: Wroclaw, Poland
Contact:

Post by Dominik Michniewski »

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
Yarin
Problemsetter
Posts: 112
Joined: Tue Sep 10, 2002 5:06 am
Location: Ume
Contact:

Moo!

Post by Yarin »

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
Subeen
Experienced poster
Posts: 127
Joined: Tue Nov 06, 2001 2:00 am
Location: Bangladesh
Contact:

Post by Subeen »

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... :(
Yarin
Problemsetter
Posts: 112
Joined: Tue Sep 10, 2002 5:06 am
Location: Ume
Contact:

Post by Yarin »

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.
choyon_buet
New poster
Posts: 5
Joined: Mon Feb 24, 2003 5:28 pm
Location: BANGLADESH

how is that?

Post by choyon_buet »

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
User avatar
saiqbal
New poster
Posts: 36
Joined: Wed Aug 07, 2002 4:52 pm
Location: Dhaka, Bangladesh
Contact:

Post by saiqbal »

its possible bcoz its an special judge problem.
an special corrector program is written for this problem to ignore small precision error. :)
hridoy
New poster
Posts: 21
Joined: Tue May 08, 2007 10:30 am
Location: Dhaka
Contact:

10320(Needed formula)

Post by hridoy »

Can anyone plz tell me How can I evaluate the formula when R>(l+w)??
CMG
New poster
Posts: 37
Joined: Sat Dec 08, 2007 5:01 am
Location: ...

Post by CMG »

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.
Sh0rty
New poster
Posts: 1
Joined: Mon Nov 17, 2008 3:02 pm

Re: 10320 - Cow Trouble! Help Please!!

Post by Sh0rty »

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.
DD
Experienced poster
Posts: 145
Joined: Thu Aug 14, 2003 8:42 am
Location: Mountain View, California
Contact:

Re: 10320 - Cow Trouble! Help Please!!

Post by DD »

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.
Post Reply

Return to “Volume 103 (10300-10399)”