#유형 : 시뮬레이션
# 예외처리만 잘 생각하면서 구현하면 난이도는 높지 않은데, 벽에 부딪히면 게임이 끝나는 부분이나 사과가 있을때 없을때 잘 구분하여 처리하면 된다.. 항상 느끼지만 시뮬레이션은 코드를 너무 못나게 짜는거 같다.
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
package bj;
import java.awt.Point;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.StringTokenizer;
public class p3190 {
static int N,K,L;
static int cnt=0;
static int dir=1;
static int moveX[] = {0,1,0,-1};
static int moveY[] = {-1,0,1,0};
static int apple[][];
static ArrayList<Point> arrList = new ArrayList<>();
static ArrayList<Info> info = new ArrayList<>();
public static void main(String[] args) throws NumberFormatException, IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
N = Integer.parseInt(br.readLine());
apple = new int[N][N];
StringTokenizer st;
K = Integer.parseInt(br.readLine());
for(int k=0; k<K; k++) {
st = new StringTokenizer(br.readLine());
int y = Integer.parseInt(st.nextToken());
int x = Integer.parseInt(st.nextToken());
apple[y-1][x-1] = 1;
}
L = Integer.parseInt(br.readLine());
for(int l=0; l<L; l++) {
st = new StringTokenizer(br.readLine());
int time = Integer.parseInt(st.nextToken());
char dir = st.nextToken().charAt(0);
info.add(new Info(time,dir));
}
solve(0,0);
}
public static void solve(int i, int j) {
while(true) {
while(cnt<next) {
arrList.add(new Point(j,i));
int newY = i + moveY[dir];
int newX = j + moveX[dir];
if(!(0<=newY && newY<N && 0<=newX && newX<N)) {
System.out.println(cnt+1);
return;
}
if(check(newY,newX)) {
System.out.println(cnt+1);
return;
}else {
if(apple[newY][newX]!=1) {
}else if(apple[newY][newX]==1)
apple[newY][newX]=0;
i = newY;
j = newX;
cnt++;
}
}
if(d == 'L') {
if(dir==0)
dir=3;
else
dir--;
dir%=4;
}else if(d == 'D') {
dir++;
dir%=4;
}
}
///방향전환끝나고나서 돌아야함
while(!check(i,j)) {
int newX = j + moveX[dir];
int newY = i + moveY[dir];
if(!(0<=newX && newX<N && 0<=newY && newY<N)) {
System.out.println(cnt+1);
return;
}
if(check(newY,newX)) {
System.out.println(cnt+1);
return;
}else {
}
i = newY;
j = newX;
cnt++;
}
}
System.out.println(cnt);
}
}
public static boolean check(int i, int j) {
return true;
return false;
}
public static class Info{
int time;
char dir;
public Info(int t, char d) {
this.time=t;
this.dir=d;
}
}
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none;color:white">cs |
'백준' 카테고리의 다른 글
#백준_3055 탈출 - Java 자바 (0) | 2020.02.05 |
---|---|
#백준_1043 거짓말 - Java 자바 (0) | 2020.02.03 |
#백준_1120 문자열 - Java 자바 (0) | 2020.01.31 |
#백준_1342 행운의 문자열 - Java 자바 (0) | 2020.01.31 |
#백준_1022 소용돌이 예쁘게 출력하기 - Java 자바 (0) | 2020.01.31 |