1.

/**
* FWP, Ausgewählte Probleme aus dem ACM Programming Contest, WS09
* Problem: 808 - Bee Breeding
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=10&page=show_problem&problem=749
*
* @author Dennis Wilfert
* @version 1.0, 12/22/2009
*
* Status : Accepted
* Runtime: 1.472
*/
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

class BeeBreeding {

public static void main(String[] args) throws IOException {

BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
PrintWriter writer = new PrintWriter(new BufferedOutputStream(System.out));
StringTokenizer token;
token = new StringTokenizer(reader.readLine());
int a = Integer.parseInt(token.nextToken());
int b = Integer.parseInt(token.nextToken());
int x, y, x2, y2, dist, current, count, i;

x = 0;
y = 0;
dist = 0;
current = 5;
count = 0;

Fract[] precalc = new Fract[10000];

// Die koordinaten für die 10000 Werte vorberechnen.
for (i = 0; i < 10000; i++) {
precalc[i] = new Fract(x, y);
if (count == dist) {
count = 0;
current++;

}
if (current == 6) {
count = current = 0;
dist++;
y += yCo(5);

} else {
x += xCo(current);
y += yCo(current);

}

count++;
}

while (a != 0) {

// Die Distanz vom 1. Wert zum zweiten Wert berechnen
dist = 0;
current = 5;
count = 0;
x = precalc[a - 1].x;
y = precalc[a - 1].y;
x2 = precalc[b - 1].x;
y2 = precalc[b - 1].y;
while (!(x == x2 && y == y2)) {
if (count == dist) {
count = 0;
current++;

}
if (current == 6) {
count = current = 0;
dist++;
y += yCo(5);

} else {
x += xCo(current);
y += yCo(current);

}
count++;
}
writer.printf("The distance between cells %d and %d is %d.%n", a, b, dist);

token = new StringTokenizer(reader.readLine());
a = Integer.parseInt(token.nextToken());
b = Integer.parseInt(token.nextToken());
}
writer.flush();
}

static int xCo(int current) {
switch (current) {
case 0:
return -1;
case 1:
return -1;
case 2:
return 0;
case 3:
return 1;
case 4:
return 1;
case 5:
return 0;
}
return 0;
}

static int yCo(int current) {
switch (current) {
case 0:
return -1;
case 1:
return 0;
case 2:
return 1;
case 3:
return 1;
case 4:
return 0;
case 5:
return -1;
}
return 0;
}
}

class Fract {

int x;
int y;

public Fract(int num, int denom) {
this.x = num;
this.y = denom;
}
}