File tree 1 file changed +63
-0
lines changed
1 file changed +63
-0
lines changed Original file line number Diff line number Diff line change
1
+ import java .io .BufferedReader ;
2
+ import java .io .IOException ;
3
+ import java .io .InputStreamReader ;
4
+ import java .util .StringTokenizer ;
5
+
6
+ /**
7
+ * 백준 1959번 달팽이3
8
+ * 꺾어지는 횟수와 끝나는 좌표 나눠서 구하기
9
+ */
10
+
11
+ public class Main {
12
+ public static void main (String [] args ) throws IOException {
13
+ BufferedReader br = new BufferedReader (new InputStreamReader (System .in ));
14
+ StringTokenizer st = new StringTokenizer (br .readLine ());
15
+
16
+ long M = Integer .parseInt (st .nextToken ());
17
+ long N = Integer .parseInt (st .nextToken ());
18
+
19
+ long count = 0 ;
20
+ long x = 0 ;
21
+ long y = 0 ;
22
+
23
+ /**
24
+ * M = 5, N = 3일 경우 5
25
+ * M = 3, N = 5일 경우 4
26
+ * M = 4, N = 4일 경우 10
27
+ */
28
+
29
+ if (M > N ) {
30
+ count = (N - 1 ) * 2 + 1 ;
31
+ } else {
32
+ count = (M - 1 ) * 2 ;
33
+ }
34
+
35
+ if (M == N ) {
36
+ if (M % 2 == 0 ) { // 짝수일 경우
37
+ x = M / 2 + 1 ;
38
+ y = N / 2 ;
39
+ } else { // 홀수일 경우
40
+ x = M / 2 + 1 ;
41
+ y = N / 2 + 1 ;
42
+ }
43
+ } else if (M > N ) {
44
+ if (N % 2 == 0 ) {
45
+ x = N / 2 + 1 ;
46
+ y = N / 2 ;
47
+ } else {
48
+ x = N / 2 + 1 + (M - N );
49
+ y = N / 2 + 1 ;
50
+ }
51
+ } else {
52
+ if (M % 2 == 0 ) {
53
+ x = M / 2 + 1 ;
54
+ y = M / 2 ;
55
+ } else {
56
+ x = M / 2 + 1 ;
57
+ y = M / 2 + 1 + (N - M );
58
+ }
59
+ }
60
+
61
+ System .out .println (count + "\n " + x + " " + y );
62
+ }
63
+ }
You can’t perform that action at this time.
0 commit comments