import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
final boolean[] field;
final int x, y;
final int hop;
field = new boolean[9];
activate(x, y);
this.x = x;
this.y = y;
this.hop = 0;
}
this.
field = Arrays.
copyOf(field.
field,
9); activate(tx, ty);
this.x = tx;
this.y = ty;
this.hop = field.hop + 1;
}
private void activate(int x, int y) {
if (isActive(x, y))
throw new AssertionError("Active cell");
field[x + 3 * y] = true;
}
private boolean isActive(int x, int y) {
return field[x + 3 * y];
}
boolean isConnectable(int x0, int y0, int x1, int y1) {
if (!isActive(x0, y0))
throw new AssertionError("Non-active cell");
if (isActive(x1, y1))
return false;
int dx
= Math.
abs(x0
- x1
); int dy
= Math.
abs(y0
- y1
);
if (x1 == x0 && dy == 2 && !isActive(x1, 1))
return false;
if (y1 == y0 && dx == 2 && !isActive(1, y1))
return false;
if (dx == dy && dx == 2 && !isActive(1, 1))
return false;
return true;
}
}
public class Main {
public static void main
(String[] args
) { int idx = 0;
List<Field> a = new ArrayList<Field>();
for (int x = 0; x < 3; x++) {
for (int y = 0; y < 3; y++) {
}
}
while (idx < a.size()) {
Field currentField
= a.
get(idx
); nextStep(a, currentField);
idx++;
}
int c = 0;
if (field.hop >= 4)
c++;
}
public static void nextStep
(List
<Field
> a,
Field field
) { for (int x = 0; x < 3; x++) {
for (int y = 0; y < 3; y++) {
if (field.isConnectable(field.x, field.y, x, y)) {
a.
add(new Field(field, x, y
)); }
}
}
}
}
aW1wb3J0IGphdmEudXRpbC5BcnJheUxpc3Q7CmltcG9ydCBqYXZhLnV0aWwuQXJyYXlzOwppbXBvcnQgamF2YS51dGlsLkxpc3Q7CgpjbGFzcyBGaWVsZCB7CglmaW5hbCBib29sZWFuW10gZmllbGQ7CglmaW5hbCBpbnQgeCwgeTsKCWZpbmFsIGludCBob3A7CgoJRmllbGQoaW50IHgsIGludCB5KSB7CgkJZmllbGQgPSBuZXcgYm9vbGVhbls5XTsKCQlhY3RpdmF0ZSh4LCB5KTsKCQl0aGlzLnggPSB4Ow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