삼성 SW 역량테스트 기출문제
주사위 전개도를 보고 이해하기가 너무 힘들었다.
근데 어차피 주사위는 처음에 0으로 시작하니까 저 전개도를 너무 의식할 필요 없다고 생각한다.
주사위를 굴릴 때 자기가 지정해준 인덱스 번호만 기억해주면 되니깐.
문제에 주사위의 윗면이 1이고 동쪽이 3이라고 해서 이걸 참고로 내 임의대로 주사위를 배열로 만들어 주었다.
상대적인 위치를 지정해 주는 것이다
나 같은 경우는 위쪽면을 1 아래쪽면을6 오른쪽 3 왼쪽 2 앞면 5 뒷면 4로 두었다.
그다음에 조건대로 구현을 하면 된다.
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
|
public class Main {
static int n,m,x,y,k;
static int map[][];
static int dx[] = {0,0,-1,1};
static int dice[];
static int dy[] = {1,-1,0,0};
static Queue<Integer> q = new LinkedList<>();
static ArrayList<Integer>direction = new ArrayList<>();
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] t = br.readLine().split(" ");
n = Integer.parseInt(t[0]);
m = Integer.parseInt(t[1]);
x = Integer.parseInt(t[2]);
y = Integer.parseInt(t[3]);
k = Integer.parseInt(t[4]);
map = new int[n][m];
dice = new int[7];
for(int i=0; i<n; i++) {
String[] input = br.readLine().split(" ");
for(int j=0; j<input.length; j++) {
map[i][j]= Integer.parseInt(input[j]);
}
}
String order[] = br.readLine().split(" ");
for(int i=0; i<order.length; i++) {
q.add(Integer.parseInt(order[i]));
}
solve();
}
public static void solve() {
while(!q.isEmpty()) {
int d = q.poll();
int nx = x+dx[d-1];
int ny = y+dy[d-1];
if(nx>=0 && ny>=0 && nx<n && ny<m) {
change_dice(d);
if(map[nx][ny]==0) {
map[nx][ny]=dice[6];
}
else {
dice[6]=map[nx][ny];
map[nx][ny]=0;
}
System.out.println(dice[1]);
x = nx;
y = ny;
}
}
}
public static void change_dice(int d) {
int temp[] = new int[7];
for(int i=1; i<=6; i++) {
temp[i]=dice[i];
}
switch(d) {
case 1: // 동쪽으로 굴릴때
dice[1]=temp[2];
dice[3]=temp[1];
dice[6]=temp[3];
dice[2]=temp[6];
break;
case 2: // 서쪽으로 굴릴 때
dice[1]=temp[3];
dice[2]=temp[1];
dice[6]=temp[2];
dice[3]=temp[6];
break;
case 3: // 북쪽으로 굴릴 때
dice[4]=temp[1];
dice[6]=temp[4];
dice[5]=temp[6];
dice[1]=temp[5];
break;
case 4: // 남쪽으로 굴릴 때
dice[5] = temp[1];
dice[6]=temp[5];
dice[4]=temp[6];
dice[1]=temp[4];
break;
}
}
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|
s |
'알고리즘' 카테고리의 다른 글
[백준 1316] 그룹 단어 체커 -JAVA //le_effort// (0) | 2020.03.11 |
---|---|
[백준 14891] 톱니바퀴 -JAVA //le_effort// (0) | 2020.03.11 |
[백준 3568] iSharp -JAVA //le_effort// (0) | 2020.03.11 |
[백준 5557] 1학년 -JAVA // le_effort// (0) | 2020.03.11 |
[백준 1495] 기타리스트 - JAVA // le_effort// (0) | 2020.03.10 |