918 - ASCII Mandelbrot

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

Moderator: Board moderators

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

918 - ASCII Mandelbrot

Post by StanleY Yelnats » Fri Oct 06, 2006 1:46 pm

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
Location: Dhaka, Bangladesh
Contact:

Post by Jan » Fri Oct 06, 2006 9:54 pm

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

Post by StanleY Yelnats » Sat Oct 07, 2006 4:06 pm

oops :oops:
thanx!

..
A great helper
Posts: 454
Joined: Thu Oct 18, 2001 2:00 am
Location: Hong Kong

Post by .. » Sun Oct 15, 2006 5:48 pm

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:
  • Please make discussion about the algorithm BRFORE posting source code.
    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
Location: Dhaka, Bangladesh
Contact:

Post by Jan » Sun Oct 15, 2006 6:30 pm

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

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

Caution on Long Doubles

Post by friggstad » Wed Oct 18, 2006 3:17 am

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

Post by kn » Wed Apr 25, 2007 1:22 pm

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
Location: Dhaka, Bangladesh
Contact:

Post by Jan » Wed Apr 25, 2007 8:15 pm

Read again
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

Post by kn » Thu Apr 26, 2007 3:08 pm

Your advice helps...thx...:D

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
Location: Dhaka, Bangladesh
Contact:

Post by Jan » Sat Apr 28, 2007 10:42 pm

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

Post by kn » Sun Jun 17, 2007 7:09 pm

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 :D

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

Re: 918 - ASCII Mandelbrot

Post by metaphysis » Mon Mar 13, 2017 10:24 am

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);
...

Post Reply

Return to “Volume 9 (900-999)”