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