UVa problem 11494(Queen)
You can read problem description here.
Solution is very easy. All you need to know is how Queen moves in the board.
You can easily see maximum of 2 moves required for a Queen to move from one location to another.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
public class Main { | |
public static void main(String[] args) { | |
Scanner sc = new Scanner(System.in); | |
while (true) { | |
int a = sc.nextInt(); | |
int b = sc.nextInt(); | |
int c = sc.nextInt(); | |
int d = sc.nextInt(); | |
if (a == 0) | |
break; | |
if (a == c && b == d) | |
System.out.println(0); | |
else if (Math.abs(a - c) == Math.abs(b - d) || a == c || b == d) | |
System.out.println(1); | |
else | |
System.out.println(2); | |
} | |
sc.close(); | |
} | |
} |
Comments
Post a Comment