不准访问
- 积分
- 104
- 大米
- 颗
- 鳄梨
- 个
- 水井
- 尺
- 蓝莓
- 颗
- 萝卜
- 根
- 小米
- 粒
- 学分
- 个
- 注册时间
- 2012-7-20
- 最后登录
- 1970-1-1
|
class robot{.--
int[] pos;
Set<String> visited;. Χ
Stack<int[]> stack;
Stack<Integer> actions;
robot(){. 1point 3 acres
pos = new int[]{0, 0};. Waral dи,
visited = new HashSet<>();
stack = new Stack<>();. 1point3acres
stack.push(new int[]{0,0,0});
actions = new Stack<>();
}
private boolean move(){}
. 1point3acres
private void turnLeft(){}. Waral dи,
private void turnRight(){}
private boolean moveF(){
boolean succ = move();
if(succ). 1point 3acres
pos[1]++;
return succ;
}
private boolean moveL(){
turnLeft(1);
boolean succ = move();
if(succ)-baidu 1point3acres
pos[0]--;
turnRight(1);
return succ;
}
private boolean moveR(){
turnRight(1);. Χ
boolean succ = move();
if(succ).
pos[0]++;
turnLeft(1);
return succ;. .и
}.google и
private boolean moveB(){
turnLeft(2);
boolean succ = move();
. Waral dи, if(succ)
pos[1]--;
turnRight(2);. 1point3acres.com
return succ;. 1point3acres.com
}
. Waral dи,. 1point 3acres
private boolean moveNext(int x){. 1point 3acres
if(x == 0) return moveF();
else if(x == 1) return moveR();
else if(x == 2) return moveB(); ..
else if(x == 3) return moveL();
return false;
}
private void Return(int x){
. check 1point3acres for more. if(x == 0) moveB();
else if(x == 1) moveL();
else if(x == 2) moveF();
else if(x == 3) moveR();
}
private void clean(){}
. 1point3acres.com
private void traverse(){
while(!stack.isEmpty()){
int[] cur = stack.peek();
int x = cur[0], y = cur[1];
if(!visited(posStr(cur[0], cur[1]))){.
visited.add(posStr(cur[0], cur[1]));
clean();
}
String[] nextPoint = new String[]{posStr(cur[0], cur[1]+1),posStr(cur[0]+1, cur[1]),
posStr(cur[0], cur[1]-1),posStr(cur[0]-1, cur[1])};
while(cur[2] < 4 && (visited.contains(nextPoint(cur[2])) || !moveNext(cur[2])))
cur[2]++;
if(cur[2] == 4){
stack.pop();
while(!stack.isEmpty() && !(pos[0] == stack.peek()[0] && pos[1] == stack.peek()[1])){
Return(actions.pop());
}
}else{
cur[2]++;
stack.push(new int[]{pos[0], pos[1], 0});
}
}
}
}
. .и |
|