-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path로봇.java
More file actions
76 lines (61 loc) · 2.13 KB
/
로봇.java
File metadata and controls
76 lines (61 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import java.io.*;
import java.util.*;
public class Main {
static int r, c, k;
static int[] d, robot;
static boolean[][] trap;
static int[] dx = {0, -1, 1, 0, 0};
static int[] dy = {0, 0, 0, -1, 1};
static StringTokenizer st;
static StringBuilder sb = new StringBuilder();
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
public static void main(String[] args) throws Exception{
preSetting();
move();
sb.append(robot[0]).append(" ").append(robot[1]);
bw.append(sb);
bw.close();
}
static void move(){
int nx, ny, idx, combo;
idx = 0;
combo = 0;
while(combo < 4){
nx = robot[0] + dx[d[idx]];
ny = robot[1] + dy[d[idx]];
if(nx < 0 || ny < 0 || r <= nx || c <= ny || trap[nx][ny]) {
idx++;
if(idx == 4) idx = 0;
combo++;
continue;
}
trap[nx][ny] = true;
robot[0] = nx;
robot[1] = ny;
combo = 0;
}
}
static void preSetting() throws Exception{
st = new StringTokenizer(br.readLine());
r = Integer.parseInt(st.nextToken());
c = Integer.parseInt(st.nextToken());
k = Integer.parseInt(br.readLine());
trap = new boolean[r][c];
robot = new int[2];
d = new int[4];
int x, y;
for(int i = 0; i < k; i++){
st = new StringTokenizer(br.readLine());
x = Integer.parseInt(st.nextToken());
y = Integer.parseInt(st.nextToken());
trap[x][y] = true;
}
st = new StringTokenizer(br.readLine());
robot[0] = Integer.parseInt(st.nextToken());
robot[1] = Integer.parseInt(st.nextToken());
trap[robot[0]][robot[1]] = true;
st = new StringTokenizer(br.readLine());
for(int i = 0; i < 4; i++) d[i] = Integer.parseInt(st.nextToken());
}
}