## 918 - ASCII Mandelbrot

Moderator: Board moderators

StanleY Yelnats
New poster
Posts: 12
Joined: Tue Sep 12, 2006 6:54 pm

### 918 - ASCII Mandelbrot

I don't know what's wrong with my code,
seems it's bigger than a precision problem
any sugestions?

Code: Select all

``````//ACC
``````
Last edited by StanleY Yelnats on Sat Oct 07, 2006 4:50 pm, edited 1 time in total.

Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Contact:

Code: Select all

``````int test(double x,double y)
{
double zr=0,zi=0;
int k=0;
double d = 0;
while (d<=2.00000001 && k<=12)
{
zr = zr*zr - zi*zi;
// You have changed zr
zi = 2*zr*zi;
// You are using the wrong zr (updated one)
zr += x;
zi += y;
k++;
d= sqrt(zr*zr + zi*zi);
}
return k;
} ``````
Hope it helps.
Ami ekhono shopno dekhi...
HomePage

StanleY Yelnats
New poster
Posts: 12
Joined: Tue Sep 12, 2006 6:54 pm
oops
thanx!

..
A great helper
Posts: 454
Joined: Thu Oct 18, 2001 2:00 am
Location: Hong Kong
Although I get AC, I am still confused.

For first input:
-1.2 1.2 0.1 -2 1 0.05

So in the graph,
I is { -1.2, -1.1, -1.0, ..., 1.1, 1.2 } 25 rows
R is { -2, -1.95, -1.9, ..., 0.9, 0.95, 1.00} 61 columns
But the sample output has 25 rows and 60 columns only.

I try to submit a program that will generate 61 columns, and I get WA.
Here is the loop part in my program:

Code: Select all

``````row = floor((MaxI - MinI) / PrecI + 1e-12) + 1;
col = floor((MaxR - MinR) / PrecR + 1e-12) + 1;
for (i = 0; i < row; i++) {
for (j = 0; j < col; j++) {
}
}
``````
Then I change my program to

Code: Select all

``````for (I = MinI; I <= MaxI; I += PrecI)
for (R = MinR; R <= MaxR; R += PrecR)
{
.......
}
``````
Now my program generate the same output as sample output and get AC.

Can anyone tell me what's wrong? It is my silly mistake or there is precision error on the judge data???? Thanks
My signature:
We can learn much more in discussion than reading source code.
• I HATE testing account.
• Don't send me source code for debug.

Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Contact:
The judge data is wrong. I have mailed about this problem in the bugs and suggestions forum. But they haven't replied yet.
Ami ekhono shopno dekhi...
HomePage

New poster
Posts: 4
Joined: Wed Oct 18, 2006 3:08 am

### Caution on Long Doubles

I also used the loop

Code: Select all

``````for (im = min_i; im <= max_i; im += prec_i) {
for (re = min_r; re <= max_r; re += prec_r) {
...
}
}
``````
where im & re were of both of type 'long double' and recieved WA. I changed them to simply 'double' and got AC.

kn
New poster
Posts: 28
Joined: Fri Apr 13, 2007 8:53 am
Sorry, one silly question:
For the iteration,
Z = Z^2 + C

what is C?
I have read through the question for several times
but still can't figure out what C is...

Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Contact:
The test is based on the equation Z = Z^2 + C. C represents a constant number, meaning that it does not change during the testing process. C is the number we are testing, the point on the complex plane that will be plotted when testing is complete.
Hope it helps.
Ami ekhono shopno dekhi...
HomePage

kn
New poster
Posts: 28
Joined: Fri Apr 13, 2007 8:53 am

Yet.. I'm confused by the dimension...
There should be sth wrong in the for loop...
making me receiving WA..

Code: Select all

``ACed[code]``
Last edited by kn on Sun Jun 17, 2007 7:09 pm, edited 1 time in total.

Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Contact:
Your code doesn't pass the first sample. Check the first sample (13th line).

Hope it helps.
Ami ekhono shopno dekhi...
HomePage

kn
New poster
Posts: 28
Joined: Fri Apr 13, 2007 8:53 am
Jan wrote:Your code doesn't pass the first sample. Check the first sample (13th line).

Hope it helps.
At the first time when you gave me your hint, I can't figure out why my code gave wrong output.
Now, I recognized what's wrong in my code...!

ROUND-OFF ERROR!!

Thx again, Jan

metaphysis
Experienced poster
Posts: 139
Joined: Wed May 18, 2011 3:04 pm

### Re: 918 - ASCII Mandelbrot

The description of problem is not so clear.
Z = Z * Z + C means:
Given a complex number C = 1 + i
iteration 1: Z = 0 + C = 1 + i, d = sqrt(1 + 1) = sqrt(2);
iteration 2: Z = (1 + i) * (1 + i) + (1 + i) = 1 + 3i, d = sqrt(1 + 9) = sqrt(10);
...