1.

package sem2.am.beemaja;

/**
* Angewandte Mathematik, SS11
* Problem: 10182 - Bee Maja
* Link: http://uva.onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=1123
*
* @author Florian Stein
* @author Franz Sommer
* @version 1.0, 06/27/2011
*
* Method : Ad-Hoc
* Status : Accepted
* Runtime: 0.336
*/

import java.awt.Point;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

public static void main(String... args) throws IOException {

// die arraylist, welche die Maja Koordinaten enthaelt. Der Index
// entspricht der entsprechenden Koordinate von Willi
ArrayList<Point> coords = new ArrayList<Point>();

// erste posi statisch
coords.add(new Point(0, 0));

// precalc restliche koordinaten bis 100000
int ring = 1;
int x = 0;
int y = 0;

// bis 100000 voll
while (coords.size() <= 100000) {

// eigentliches fuellen, nach jedem schritt in einem kreis wird die
// neue position zur arraylist hinzugefuegt.
y++;
coords.add(new Point(x, y));

// je nach ring/radius wiederholen
for (int j = 0; j < ring - 1; j++) {
x--;
y++;
coords.add(new Point(x, y));
}

for (int j = 0; j < ring; j++) {
x--;
coords.add(new Point(x, y));

}

for (int j = 0; j < ring; j++) {
y--;
coords.add(new Point(x, y));
}

for (int j = 0; j < ring; j++) {
x++;
y--;
coords.add(new Point(x, y));

}
for (int j = 0; j < ring; j++) {
x++;
coords.add(new Point(x, y));

}
for (int j = 0; j < ring; j++) {
y++;
coords.add(new Point(x, y));
}
// einen ring weiter nach aussen gehen
ring++;
}

// der scanner zum einlesen
Scanner sc = new Scanner(System.in);

// solange der scanner weitere werte hat
while (sc.hasNext()) {

// nummer einlesen
int number = sc.nextInt();

// falls groesser 100000 oder 0 -> programm beenden
if (number == 0 || number > 100000) {
break;
}

// ausgabe der entsprechenden koordinate in maja's koordinaten
// system.
System.out.println(coords.get(number - 1).x + " "
+ coords.get(number - 1).y);
}
}
}



1.

/**
* FWP, Ausgewählte Probleme aus dem ACM Programming Contest, WS10/11
* Problem: 10182 Bee Maja
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&page=show_problem&problem=1123
*
* @author Patrick Bédat
* @version 1.0, 10/27/2010
*
* Method : Simulation
* Status : Accepted
* Runtime: 0.892
*/

import java.awt.Point;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;

public class Main
{

private static Map<Integer, Point> fieldCoords = new HashMap<Integer, Point>();

public static void main(String... args) throws IOException
{
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(reader.readLine());
int field = Integer.parseInt(st.nextToken());
while (true)
{
if (!fieldCoords.containsKey(field));
calculateCoords(field);

Point coord = fieldCoords.get(field);

System.out.printf("%d %d%n", coord.x, coord.y);

if (reader.ready())
{
st = new StringTokenizer(reader.readLine());
field = Integer.parseInt(st.nextToken());
}
else
break;
}
}

private static void calculateCoords(int field2)
{
int radius = 1;
int x = 0;
int y = 0;

fieldCoords.put(1, new Point(0, 0));

int currentField = 2;
while (currentField <= field2)
{
y++;
fieldCoords.put(currentField++, new Point(x, y));

for (int j = 0; j < radius - 1; j++)
{
x--;
y++;
fieldCoords.put(currentField++, new Point(x, y));
}

for (int j = 0; j < radius; j++)
{
x--;
fieldCoords.put(currentField++, new Point(x, y));
}

for (int j = 0; j < radius; j++)
{
y--;
fieldCoords.put(currentField++, new Point(x, y));
}

for (int j = 0; j < radius; j++)
{
x++;
y--;
fieldCoords.put(currentField++, new Point(x, y));
}
for (int j = 0; j < radius; j++)
{
x++;
fieldCoords.put(currentField++, new Point(x, y));
}
for (int j = 0; j < radius; j++)
{
y++;
fieldCoords.put(currentField++, new Point(x, y));
}

radius++;
}
}
}