Algorithm 문제풀이/simulation
[BOJ] 백준 17143-낚시왕(java)
cjsong
2019. 8. 29. 23:58
정렬이 중요
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
|
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.StringTokenizer;
public class Main{
private static int M;
private static int[][] map;
private static int C;
private static int R;
private static int result;
private static ArrayList<Info> list;
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine(), " ");
R = Integer.parseInt(st.nextToken());
C = Integer.parseInt(st.nextToken());
M = Integer.parseInt(st.nextToken());
list = new ArrayList<Info>();
for (int k = 0; k < M; k++) {
st = new StringTokenizer(br.readLine(), " ");
int r = Integer.parseInt(st.nextToken());
int c = Integer.parseInt(st.nextToken());
int s = Integer.parseInt(st.nextToken()); // 속력
int d = Integer.parseInt(st.nextToken()); // 방향
int z = Integer.parseInt(st.nextToken()); // 크기
list.add(new Info(r, c, s, d, z));
}
result = 0;
process();
System.out.println(result);
}// end of main
public static void process() {
int fisherIndex = 0;
while (fisherIndex != C) {
fisherIndex++;
for (Info info : list) {
if (fisherIndex == info.c) {
result += info.z;
break;
}
}
map = new int[R+1][C+1];
move();
}
}
}
public static void move() {
// 1~4 상하 우좌
for (Info info : list) {
int count = 0;
while (count != info.s) {
count++;
switch (info.d) {
case 1:
if (info.r > 1) {
info.r = info.r - 1;
continue;
} else {
count--;
info.d = 2;
}
break;
case 2:
if (info.r < R) {
info.r = info.r + 1;
continue;
} else {
count--;
info.d = 1;
}
break;
case 3:
if (info.c < C) {
info.c = info.c + 1;
continue;
} else {
count--;
info.d = 4;
}
break;
case 4:
if (info.c > 1) {
info.c = info.c - 1;
continue;
} else {
count--;
info.d = 3;
}
break;
default:
break;
}
}
if(map[info.r][info.c] < info.z) map[info.r][info.c] = info.z;
}
}
public static class Info implements Comparable<Info> {
int r;
int c;
int s;// 속력
int d;// 방향
int z;// 크기
public Info(int r, int c, int s, int d, int z) {
super();
this.r = r;
this.c = c;
this.s = s;
this.d = d;
this.z = z;
}
@Override
public int compareTo(Info o) {
if (o.c != this.c) {
return this.c - o.c;
} else if (o.c == this.c && o.r != this.r) {
return this.r - o.r;
}
return o.z- this.z;
}
@Override
public String toString() {
// TODO Auto-generated method stub
return "r:" + r +" c : " + c + " 속력 " + s +" 방향" + d + " 크기" + z ;
}
}
}// end of class
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 |