10320 - Cow Trouble! Help Please!!
Moderator: Board moderators
This is strange -- I get AC now.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
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.
10320 cow trouble
my code gets WA. 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...
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.
-
- Guru
- Posts: 834
- Joined: Wed May 29, 2002 4:11 pm
- Location: Wroclaw, Poland
- Contact:
Are yot sure that
is similar to
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
Code: Select all
printf("%0.10lf" ....
Code: Select all
printf("%.10lf" ....
I don't try to solve this question yet and I can't say any word about your algorithm
Best greetings
Moo!
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
Try the input
7 3 9
9 5 2
18 2 7
The correct answer should be
222.2676802415
9.4247779608
135.0884841044
-
- New poster
- Posts: 5
- Joined: Mon Feb 24, 2003 5:28 pm
- Location: BANGLADESH
how is that?
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 .
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?
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?
10320(Needed formula)
Can anyone plz tell me How can I evaluate the formula when R>(l+w)??
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.
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.
Re: 10320 - Cow Trouble! Help Please!!
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.
-
- Experienced poster
- Posts: 145
- Joined: Thu Aug 14, 2003 8:42 am
- Location: Mountain View, California
- Contact:
Re: 10320 - Cow Trouble! Help Please!!
The most tricky case happens when R > l + w. You need to solve some equations first to get the final answer.
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?