/* Solution for DrHorrible from ICPC-PACNW-2011 problem set Author: Kyle Parker-Robinson Date: 9/12/11 */ import java.util.*; import java.io.*; public class DrHorrible { int width, height; Map> squares; public DrHorrible() throws Exception { Scanner in = new Scanner(System.in); int boardCount = 0; height = in.nextInt(); width = in.nextInt(); in.nextLine(); while(height != 0) { boardCount++; System.out.println("Board " + boardCount + ":"); this.squares = new HashMap>(width * height); String line = in.nextLine(); while(!line.equals("0")) { String[] tokens = line.split(" "); int num = Integer.parseInt(tokens[0]); Map square = new HashMap(num); for(int i=1; i (width * height) - width) { solved = true; } else { nextSquare = curSquare+width; nextPoint = "B"; } break; case 'F': if(curSquare > (width * height) - width) { solved = true; } else { nextSquare = curSquare+width; nextPoint = "A"; } break; case 'G': if((curSquare - 1) % width == 0) { solved = true; } else { nextSquare = curSquare-1; nextPoint = "D"; } break; case 'H': if((curSquare - 1) % width == 0) { solved = true; } else { nextSquare = curSquare-1; nextPoint = "C"; } break; } if(solved) { System.out.println(curSquare + endPoint); } else { Process(nextSquare, nextPoint); } } public static void main(String[] args) throws Exception { new DrHorrible(); } }