Grasshopper.java
import java.io.BufferedReader;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
/**
*
* @author cteam022
*/
public class Grasshopper {
/**
* @param args the command line arguments
*/
Grasshopper g = new Grasshopper();
while(true){g.uloha();}
}
if(!input.
ready()){System.
exit(0);} int a
= Integer.
valueOf(st.
nextToken()); int b
= Integer.
valueOf(st.
nextToken()); int x1
= Integer.
valueOf(st.
nextToken()); int y1
= Integer.
valueOf(st.
nextToken()); int x2
= Integer.
valueOf(st.
nextToken()); int y2
= Integer.
valueOf(st.
nextToken());
int x = x1, y = y1;
int i;
for(i
=0; Math.
abs(x
- x2
) > 2 && Math.
abs(y
- y2
)>2; i
++){ int dx = x2 - x;
int dy = y2 - y;
}else{
}
}
int p = rekurze(6, x2, y2, x, y, a, b);
if(p == 100){
System.
out.
println("impossible"); }else{
}
}
static int rekurze(int pocet, int x2, int y2, int x,int y,int a, int b){
if (pocet < 0) return 100;
if (x2 == x && y2 == y) return 0;
int min = 100;
for(int druhx = -1; druhx < 2; druhx+=2){
for(int druhy = -1; druhy < 2; druhy+=2){
if(x+druhx*2 < a && x+druhx*2>=0 && y+druhy < b && y+druhy >=0){
int r1 = rekurze(pocet - 1, x2, y2, x+druhx*2, y+druhy, a, b);
}
if(x+druhx < a && x+druhx>=0 && y+druhy*2 < b && y+druhy*2 >=0){
int r2 = rekurze(pocet - 1,x2, y2, x+druhx, y+druhy*2, a, b);
}
}
}
return min==100 ? 100 : min + 1;
}
}