1.

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
* Angewandte Mathematik, SS11
* Problem: 918 - Ascii Mandelbrot
* Link: http://uva.onlinejudge.org/external/9/918.html
* @author Fabian, Trampusch
* @author Robert Schwarz
* @version 1.0, 24.04.2011
*
* Method : Ad-Hoc
* Status : Accepted
* Runtime: 0.368
*/

public class Main {

private static final double MAX_MAGNITUDE = 4.00001;
private static final double roundDouble = 0.00000001;

public static void main(String[] args) throws NumberFormatException,
IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int numOfTestCases = Integer.parseInt(br.readLine());

for (int currentTestCase = 0; currentTestCase < numOfTestCases; currentTestCase++) {
String[] lineParts = br.readLine().split(" ");

char[] chars = lineParts[0].replace("\"", "").toCharArray();

double mini = Double.parseDouble(lineParts[1]);
double maxi = Double.parseDouble(lineParts[2]);
double preci = Double.parseDouble(lineParts[3]);
double minr = Double.parseDouble(lineParts[4]);
double maxr = Double.parseDouble(lineParts[5]);
double precr = Double.parseDouble(lineParts[6]);

// rows
for (double currenti = mini; currenti <= maxi + roundDouble; currenti += preci) {
// row
for (double currentr = minr; currentr <= maxr + roundDouble; currentr += precr) {

int i;
//System.out.println((currenti * currenti) + (currentr*currentr));
if((currenti * currenti) + (currentr*currentr) <= MAX_MAGNITUDE)
i = getIterationCount(currentr, currenti);
else
i = 0;

if (i < 12) {
System.out.print(chars[i]);
} else {
System.out.print(" ");
}
}
System.out.println();
}

if(currentTestCase < numOfTestCases - 1)
System.out.println();
}
}

public static int getIterationCount(double cx,
double cy) {

double zx = cx;
double zy = cy;
double newZx;
double newZy;

double magnitude = 0;
int i = 0;

while (i < 12 && magnitude < MAX_MAGNITUDE) {
newZx = (zx * zx) - (zy * zy) + cx;
newZy = 2 * zx * zy + cy;

zx = newZx;
zy = newZy;

magnitude = newZx * newZx + newZy * newZy;
//System.out.println(magnitude);
i++;
}

return i;
}
}


2.

/**
* FWP, Angewandte Mathematik, SS11
* Problem: 918 - ASCII - Mandelbrot
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=11&page=show_problem&problem=859
*
* @author Sebastian Stumpf
* @author Benjamin Vogt
* @version 1.0, 2011-04-21 12:18:09
*
* Method : Ad-Hoc
* Status : Accepted
* Runtime: 0.208
*/

import java.io.*;
import java.util.*;

/* Interesting Inputs
1
"1234567890AB" -1.2 1.2 0.01 -2 1 0.005

2
"#$&/|[]+;:-." -1.2 1.2 0.1 -2 1 0.05
"1234567890AB" -1.2 -0.8 0.02 -0.5 0.5 0.02

1
"1234567890AB" -0.25 0.25 0.001 -1.5 -1.0 0.001

*/

/* pay attention on rounding your values, cause double isnt exact!
* use datatype long, no bigDecimal need!
* use stringbuilder, delete stringbuilder is faster than create a new one!
*/

/**Prints a part of the plane of the Mandelbrot - Set.
*/
public class Main
{
/**Rounds a double value to given precision.
*
* @param d The Value to round.
* @param precision Number of digits after point.
* @return Rounded value.
*/
static double roundDouble(double d, int precision)
{
double n = Math.pow(10, precision);
return (Math.floor(d * n + 0.5) / n);
}

/**Checks if a Complex Number is part of the Mandelbrot - Set.
*
* Computes Z = Z^2 + C. Recursive. Z, C, complex numbers. C constant.
* Current depth = needed calls of recursion, so that
* magnitude of Z = sqrt(r^2 + i^2) > 2 => number is not part of Set.
*
* @param depth Initialize with 0, important for recursion.
* @param ratZ Initialize with 0, important for recursion.
* @param iZ Initialize with 0, important for recursion.
* @param ratConst The rational component of the Complex number to be checked.
* @param iConst The irrational component of the Complex number to be checked.
* @return The depth, for that the Number is out of the Set. If Depth > 11, return -1.
*/
static int partOfMandelbrot(int depth, double ratZ, double iZ, double ratConst, double iConst)
{
// Rule for square of a Complex.
// (a + bi)^2 = a^2 + 2*a*bi - b^2 = a^2-b^2 + 2abi
// "ratio" "irr"
if(depth > 11)
return -1;
else
{
double ratZnext = Math.pow(ratZ, 2.0) - Math.pow(iZ, 2.0) + ratConst;
double iZnext = 2.0 * ratZ * iZ + iConst;
double magnitude = Math.sqrt(Math.pow(ratZnext, 2.0) + Math.pow(iZnext, 2.0));
if(roundDouble(magnitude, 10) > 2.0)
return depth;
else
// return value is passed through the method of max depth up to the
// initial call of the method
return partOfMandelbrot(depth+1, ratZnext, iZnext, ratConst, iConst);
}
}

/**Prints the Mandelbrot - Set for a selected part of the plane.
*
* @param chars Hast to be of the exact size char[11]. chars[i] is printed, if the complex number is not part of Mandelbrot after i recursions.
* @param mini The minimal irrational coordinate of the plane.
* @param maxi The maximal irrational coordinate of the plane.
* @param preci The precision, mini is stepwise increased.
* @param minr The minimal rational coordinate of the plane.
* @param maxr The maximal rational coordinate of the plane.
* @param precr The precision, mini is stepwise increased.
*/
static void printMandelbrot(char[] chars, double mini, double maxi, double preci,
double minr, double maxr, double precr)
{
StringBuilder sb = new StringBuilder(1000000);
for(double i = mini; roundDouble(i, 10) <= maxi; i += preci)
{
for(double j = minr; roundDouble(j, 10) <= maxr; j += precr)
{
int partOfMB = partOfMandelbrot(0, .0, .0, j, i);
if(partOfMB < 0)
sb.append(" ");
else
sb.append(chars[partOfMB]);
}
sb.append("\n");
System.out.print(sb);
// deleting sb is much faster, than creating new(sb)
// you have to delete up to sb.length, to delete the char for "end of sb"
sb.delete(0, sb.length());
}
}

public static void main(String[] args) throws Exception
{
// read values
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
int tests = Integer.parseInt(input.readLine());
char[] chars = new char[12];
double mini;
double maxi;
double preci;
double minr;
double maxr;
double precr;

for(int i = 0; i < tests; i++)
{
StringTokenizer tokenizer = new StringTokenizer(input.readLine());
chars = tokenizer.nextToken().replaceAll("\"", "").toCharArray();
mini = Double.parseDouble(tokenizer.nextToken());
maxi = Double.parseDouble(tokenizer.nextToken());
preci = Double.parseDouble(tokenizer.nextToken());
minr = Double.parseDouble(tokenizer.nextToken());
maxr = Double.parseDouble(tokenizer.nextToken());
precr = Double.parseDouble(tokenizer.nextToken());
printMandelbrot(chars, mini, maxi, preci, minr, maxr, precr);
// pay attention that no blank line is printed after the last Set!!
// cost me much time to figure out that this was the cause for wa!
if(i<tests-1)
System.out.println();
}
}
}


--------------------------------------------------------------------------


1.

package asciiMandelbrot;

/**
* FWP, Ausgew√¤hlte Probleme aus dem ACM Programming Contest, WS10/11
* Problem: 918 Ascii Mandelbrot
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&page=show_problem&problem=859
*
* @author Patrick Bédat
* @author Christoph Göttschkes
* @author Philippe Brousse
* @version 1.0, 14.11.2010
*
* Method : Ad-Hoc
* Status : Accepted
* Runtime: 0.100
*/
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;

import java.util.*;

class Main
{

static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

public static void main(String[] agrs) throws IOException
{
int testCases = Integer.parseInt(reader.readLine());

for (int curCase = 0; curCase < testCases; curCase++)
{
String line = reader.readLine();
StringTokenizer tokenizer = new StringTokenizer(line);
char[] chars = tokenizer.nextToken().substring(1, 13).toCharArray();

double minImaginary = Double.parseDouble(tokenizer.nextToken());
double maxImaginary = Double.parseDouble(tokenizer.nextToken());
double precImaginary = Double.parseDouble(tokenizer.nextToken());
double minReal = Double.parseDouble(tokenizer.nextToken());
double maxReal = Double.parseDouble(tokenizer.nextToken());
double precReal = Double.parseDouble(tokenizer.nextToken());

StringBuilder builder = new StringBuilder();
for (double img = minImaginary; img <= maxImaginary + 0.00000001; img += precImaginary)
{
for (double real = minReal; real <= maxReal + 0.00000001; real += precReal)
{

int c = test(img, real, precImaginary, precReal);
if (c >= 12)
builder.append(" ");
else
builder.append(chars[c]);
}
builder.append("\n");
}
System.out.print(builder);
if (curCase < testCases - 1)
System.out.println();
}
}

static int test(double img, double real, double precImg, double precReal)
{
double magnitude = img * img + real * real;
double zImg = img;
double zReal = real;

int c = 0;

while (magnitude <= 4.000000001 + Double.MIN_VALUE && c < 20)
{
double temp = zImg;
zImg = 2 * zImg * zReal + img;
zReal = ((zReal * zReal) - (temp * temp)) + real;
magnitude = zImg * zImg + zReal * zReal;
c++;
}
return c;
}
}