## 解析

```import java.util.Scanner;
/**
* @ClassName 华为机试二星题--机器人走迷宫
*              进 # # # # #
*              # # # # 0 0
*              0 0 0 # # #
*              # # # # # 出
*/
public class HWRobotMaze01 {
public static void main(String[] args) {
// 0 是未踩过的。 1是墙。 2是踩过的。
Scanner in = new Scanner(System.in);
int x = in.nextInt();
int y = in.nextInt();
int[][] room = new int[x][y];
int wall = in.nextInt();
while(wall-->0){
int wallX = in.nextInt();
int wallY = in.nextInt();
room[wallX][wallY] = 1;
}
path(room, 0, 0, x-1, y-1);
int noWay = 0; // 不可达
for(int i =0; i< x; i++){
for(int j=0; j< y; j++){
if(room[i][j] == 9){
}else if(room[i][j] == 0){
noWay += 1;
}
}
}
}

//不可达方格 : 机器人无法通过增加X Y值到的方格.走完还是0的代表不可达
//陷阱方格 : 走到该位置不能正确走到终点的方格。 向前/向上不可达/同为陷阱方格则也标记为陷阱方格 9
//走过的为2
private static void path(int[][] room, int nextX, int nextY, int x, int y){
//判断是墙直接跳过
if(room[nextX][nextY] ==1){
return;
}
if(room[nextX][nextY] != 0){
return;
}
if(nextX == x && nextY == y){
room[nextX][nextY] = 2;
return;
}
if(nextX < x){
path(room, nextX+1, nextY, x, y);
}
if(nextY < y){
path(room, nextX, nextY+1, x, y);
}

//该点向上/向前均为不可达/陷阱方格则为陷阱方格
if(nextX == x || nextY == y){
if(nextX == x && nextY < y && room[nextX][nextY+1] != 2){
room[nextX][nextY] = 9;
}else if(nextY == y && nextX < x && room[nextX+1][nextY] != 2){
room[nextX][nextY] = 9;
}else{
room[nextX][nextY] = 2;
}
}else if(room[nextX+1][nextY] !=2 && room[nextX][nextY+1] !=2){
room[nextX][nextY] = 9;
}else{
room[nextX][nextY] = 2;
}
return;
}

}```