## 358 - Don't Have A Cow

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

Moderator: Board moderators

Faizur
New poster
Posts: 39
Joined: Fri Jun 06, 2003 3:04 pm

### Again WA

Hello shamim many many thanks for your reply. I have changed my code:

Code: Select all

``````#include<stdio.h>
#include<math.h>
#define pi 3.14159
double p;
double fn(double x)
{
return 4.0*x*cos(x)*cos(x)+pi*(1.00-p)-2.0*x-sin(2.0*x);
}
int main()
{
double x1,x2,x3,y1,y2,y3,r,R;
int N;

scanf("%d",&N);
while(N--)
{
scanf("%lf%lf",&r,&p);
x1=pi/2;
x3=0;
while(fabs(x3-x1)>0.00000000000001)
{
x2=(x1+x3)/2.0;
y2=fn(x2);
if(y2<0.0000000000000000001)
x1=x2;
else
x3=x2;
if(fabs(y2)<0.00000000000001)
{x1=x2;break;}

}
R=2*r*cos(x1);
printf("R = %.lf, P = %.2lf, Rope = %.2lf\n",r,p,R);

}

return 0;
}
``````
Still i am getting WA.So i am realy ....
Whether my formula is wrong or something else .Pls help

the LA-Z-BOy
Learning poster
Posts: 94
Joined: Wed Jul 31, 2002 12:44 pm
Contact:
dear Faizur, i haven't checked your code, i just ran it on some inputs and i am giving the i/o s that your prog didn't agree with mine.

Code: Select all

``````R = 1000, P = 0.02, Rope = 204.49
R = 1000, P = 0.06, Rope = 360.52
R = 1000, P = 0.07, Rope = 390.78
R = 1000, P = 0.08, Rope = 419.16
R = 1000, P = 0.23, Rope = 739.66
R = 1000, P = 0.28, Rope = 825.56
R = 1000, P = 0.30, Rope = 858.40
``````
...where your prog gives something different with +-0.01 or so.
ps. my method is something like bsearch but my equation is independent of PI. i just needed PI(=3.14159) to calculate the `target' area, and i used epsilon 1e-5 for this area (just because i have to keep only two decimal places after the area. both codes with double and long double got accepted.
thanks
Istiaque Ahmed [the LA-Z-BOy]

Noim
Learning poster
Posts: 88
Joined: Sun Oct 13, 2002 6:11 am
THanks shamim,

i haved missed that it was a multiple input case program. after seeing your caution i manage to get accept. THanks any way.
__nOi.m....

Dominik Michniewski
Guru
Posts: 834
Joined: Wed May 29, 2002 4:11 pm
Location: Wroclaw, Poland
Contact:
Could anyone tell me , why this program gives me WA ?
I've got right answers for every case which I find in board but OJ says WA.
Could anyone send me some more IO, on which my program fails ??
Computations are given from math books and seems to be allright

Best regards
DM

Code: Select all

``````cutted ...
``````
Last edited by Dominik Michniewski on Mon Jul 28, 2003 3:17 pm, edited 1 time in total.
If you really want to get Accepted, try to think about possible, and after that - about impossible ... and you'll get, what you want ....
Born from ashes - restarting counter of problems (800+ solved problems)

the LA-Z-BOy
Learning poster
Posts: 94
Joined: Wed Jul 31, 2002 12:44 pm
Contact:
Hello Dominik
i have Managed to figure out few mistakes in your code, i've sent the modified one via private msg.
thanks
Istiaque Ahmed
Istiaque Ahmed [the LA-Z-BOy]

Dominik Michniewski
Guru
Posts: 834
Joined: Wed May 29, 2002 4:11 pm
Location: Wroclaw, Poland
Contact:
Thanks La-z-boy for help ...
Strange are two things:
1. on windows, on my computer, all works fine - I don't have UNIX to test so it's impossible to find such errors by me
2. it's second code, in which I must calculate values with more precision, that I think taht I should ... I think, that 1e-5 should be enough, but I see that 100 more is enough ...

Thanks again and again
DM
If you really want to get Accepted, try to think about possible, and after that - about impossible ... and you'll get, what you want ....
Born from ashes - restarting counter of problems (800+ solved problems)

Faizur
New poster
Posts: 39
Joined: Fri Jun 06, 2003 3:04 pm
But whats the problem with my code.. This problem is making me really crazy....pls check my code..........................

ivec
New poster
Posts: 8
Joined: Tue May 27, 2003 2:41 pm
Contact:
I have the same output as IIUC GOLD, but still WA.

I believe I am handling the multiple input correctly (I have a bunch of assertions to validate input and check there is no trailing data).

It feels like this is one of these numeric error / rounding problems. I used some classig geometry and trigonometry do define the inverse function (ratio eaten from rope ratio), then do a simple bissective search (and I tried various accuracy thresholds).

The calculation function I use looks like: [c]
double eatenRatio(double ropeRatio)
{
double sqRope = ropeRatio*ropeRatio;
double alpha = 2*acos(1-0.5*sqRope);
double beta = 2*acos( 0.5*ropeRatio );
return 0.5*( (alpha-sin(alpha)) + sqRope*(beta-sin(beta)) ) / 3.14159; /*26535;*/
}
[/c]

Does someone who got AC use a different computation approach ?

hints welcome...

Chameleon
New poster
Posts: 4
Joined: Thu Jun 20, 2002 4:54 pm

### Output of P must be to two decimal places

I kept getting WA for this problem. I eventually guessed that the output of P must be to two decimal places, even though this is not written anywhere in the problem statement. Very annoying.

Sajid
Learning poster
Posts: 94
Joined: Sat Oct 05, 2002 5:34 pm
Location: CS - AIUB, Dhaka, Bangladesh.
Contact:

### 358 : Confused !

I thought that the following eqn is enough for this problem... but it isnt.

Code: Select all

``````Area(Rope) = Area(R) * p
PI * Rope^2 = PI * R^2 * p
Rope = R * sqrt(p)``````
But I dont understand why...

What's wrong with this?
Last edited by Sajid on Sat Dec 27, 2003 4:16 pm, edited 1 time in total.
Sajid Online: www.sajidonline.com

sohel
Guru
Posts: 856
Joined: Thu Jan 30, 2003 5:50 am
Location: New York

### No its not!

I wonder how you came up with this formula. If it were that simple, the AC percentage would have been much higher.

From what I can remember, I derived two/three equations and solved it using bisection method.

shamim
A great helper
Posts: 498
Joined: Mon Dec 30, 2002 10:10 am
Location: Bozeman, Montana, USA
Well, i guess you now know it isn't the right formula. If you stil think so, please justify yourself.

As for the actual solution, you need derive an equation which needs to be solved using Bisection method.

Sajid
Learning poster
Posts: 94
Joined: Sat Oct 05, 2002 5:34 pm
Location: CS - AIUB, Dhaka, Bangladesh.
Contact:
Well, Yes, I knew that this eqn is wrong...
But I wanted to know that what's wrong?

I am not confused to get WA...
Sajid Online: www.sajidonline.com

sjn
Learning poster
Posts: 73
Joined: Mon Apr 08, 2002 8:22 am
Contact:
I got WA several times and don't know why

i got the following result from my program
could anything check it for me?

Code: Select all

``````Input:
51
100 0.00
100 0.01
100 0.02
100 0.03
100 0.04
100 0.05
100 0.06
100 0.07
100 0.08
100 0.09
100 0.10
100 0.11
100 0.12
100 0.13
100 0.14
100 0.15
100 0.16
100 0.17
100 0.18
100 0.19
100 0.20
100 0.21
100 0.22
100 0.23
100 0.24
100 0.25
100 0.26
100 0.27
100 0.28
100 0.29
100 0.30
100 0.31
100 0.32
100 0.33
100 0.34
100 0.35
100 0.36
100 0.37
100 0.38
100 0.39
100 0.40
100 0.41
100 0.42
100 0.43
100 0.44
100 0.45
100 0.46
100 0.47
100 0.48
100 0.49
100 0.50``````
[/b]

Code: Select all

``````Output:
R = 100, P = 0.00, Rope = 0.00
R = 100, P = 0.01, Rope = 14.36
R = 100, P = 0.02, Rope = 20.45
R = 100, P = 0.03, Rope = 25.18
R = 100, P = 0.04, Rope = 29.21
R = 100, P = 0.05, Rope = 32.79
R = 100, P = 0.06, Rope = 36.05
R = 100, P = 0.07, Rope = 39.08
R = 100, P = 0.08, Rope = 41.92
R = 100, P = 0.09, Rope = 44.60
R = 100, P = 0.10, Rope = 47.16
R = 100, P = 0.11, Rope = 49.60
R = 100, P = 0.12, Rope = 51.96
R = 100, P = 0.13, Rope = 54.23
R = 100, P = 0.14, Rope = 56.43
R = 100, P = 0.15, Rope = 58.57
R = 100, P = 0.16, Rope = 60.64
R = 100, P = 0.17, Rope = 62.67
R = 100, P = 0.18, Rope = 64.65
R = 100, P = 0.19, Rope = 66.59
R = 100, P = 0.20, Rope = 68.48
R = 100, P = 0.21, Rope = 70.34
R = 100, P = 0.22, Rope = 72.17
R = 100, P = 0.23, Rope = 73.97
R = 100, P = 0.24, Rope = 75.73
R = 100, P = 0.25, Rope = 77.48
R = 100, P = 0.26, Rope = 79.19
R = 100, P = 0.27, Rope = 80.88
R = 100, P = 0.28, Rope = 82.56
R = 100, P = 0.29, Rope = 84.21
R = 100, P = 0.30, Rope = 85.84
R = 100, P = 0.31, Rope = 87.46
R = 100, P = 0.32, Rope = 89.05
R = 100, P = 0.33, Rope = 90.64
R = 100, P = 0.34, Rope = 92.20
R = 100, P = 0.35, Rope = 93.76
R = 100, P = 0.36, Rope = 95.30
R = 100, P = 0.37, Rope = 96.83
R = 100, P = 0.38, Rope = 98.34
R = 100, P = 0.39, Rope = 99.85
R = 100, P = 0.40, Rope = 101.35
R = 100, P = 0.41, Rope = 102.83
R = 100, P = 0.42, Rope = 104.31
R = 100, P = 0.43, Rope = 105.78
R = 100, P = 0.44, Rope = 107.24
R = 100, P = 0.45, Rope = 108.69
R = 100, P = 0.46, Rope = 110.14
R = 100, P = 0.47, Rope = 111.58
R = 100, P = 0.48, Rope = 113.02
R = 100, P = 0.49, Rope = 114.45
R = 100, P = 0.50, Rope = 115.87``````
[/b]

sjn
Learning poster
Posts: 73
Joined: Mon Apr 08, 2002 8:22 am
Contact:
At last i got AC
when i chose the epsilon with 1e-5 i passed it