Post

๐Ÿข PCCP 3๋ฒˆ ์•„๋‚ ๋กœ๊ทธ ์‹œ๊ณ„

1. ๋ฌธ์ œ ๋งํฌ

PCCP 3๋ฒˆ ์•„๋‚ ๋กœ๊ทธ ์‹œ๊ณ„


2. ์ฝ”๋“œ

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
"""
PCCP 3๋ฒˆ ์•„๋‚ ๋กœ๊ทธ ์‹œ๊ณ„

๐Ÿ’› ๋ฌธ์ œ
์‹œ์นจ, ๋ถ„์นจ, ์ดˆ์นจ์ด ์žˆ๋Š” ์•„๋‚ ๋กœ๊ทธ์‹œ๊ณ„๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค.
์‹œ๊ณ„์˜ ์‹œ์นจ์€ 12์‹œ๊ฐ„๋งˆ๋‹ค, ๋ถ„์นจ์€ 60๋ถ„๋งˆ๋‹ค, ์ดˆ์นจ์€ 60์ดˆ๋งˆ๋‹ค ์‹œ๊ณ„๋ฅผ ํ•œ ๋ฐ”ํ€ด ๋•๋‹ˆ๋‹ค.
๋”ฐ๋ผ์„œ ์‹œ์นจ, ๋ถ„์นจ, ์ดˆ์นจ์ด ์›€์ง์ด๋Š” ์†๋„๋Š” ์ผ์ •ํ•˜๋ฉฐ ๊ฐ๊ฐ ๋‹ค๋ฆ…๋‹ˆ๋‹ค.
์ด ์‹œ๊ณ„์—๋Š” ์ดˆ์นจ์ด ์‹œ์นจ/๋ถ„์นจ๊ณผ ๊ฒน์น  ๋•Œ๋งˆ๋‹ค ์•Œ๋žŒ์ด ์šธ๋ฆฌ๋Š” ๊ธฐ๋Šฅ์ด ์žˆ์Šต๋‹ˆ๋‹ค.
๋‹น์‹ ์€ ํŠน์ • ์‹œ๊ฐ„ ๋™์•ˆ ์•Œ๋žŒ์ด ์šธ๋ฆฐ ํšŸ์ˆ˜๋ฅผ ์•Œ๊ณ  ์‹ถ์Šต๋‹ˆ๋‹ค.

์•Œ๋žŒ์ด ์šธ๋ฆฌ๋Š” ํšŸ์ˆ˜๋ฅผ ์„ผ ์‹œ๊ฐ„์„ ๋‚˜ํƒ€๋‚ด๋Š” ์ •์ˆ˜ h1, m1, s1, h2, m2, s2๊ฐ€ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ฃผ์–ด์ง‘๋‹ˆ๋‹ค.
์ด๋•Œ, ์•Œ๋žŒ์ด ์šธ๋ฆฌ๋Š” ํšŸ์ˆ˜๋ฅผ return ํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด์ฃผ์„ธ์š”.

๐Ÿงก ์ œํ•œ ์‚ฌํ•ญ
0 โ‰ค h1, h2 โ‰ค 23
0 โ‰ค m1, m2 โ‰ค 59
0 โ‰ค s1, s2 โ‰ค 59
    h1์‹œ m1๋ถ„ s1์ดˆ๋ถ€ํ„ฐ h2์‹œ m2๋ถ„ s2์ดˆ๊นŒ์ง€ ์•Œ๋žŒ์ด ์šธ๋ฆฌ๋Š” ํšŸ์ˆ˜๋ฅผ ์„ผ๋‹ค๋Š” ์˜๋ฏธ
        h1์‹œ m1๋ถ„ s1์ดˆ < h2์‹œ m2๋ถ„ s2์ดˆ
        ์‹œ๊ฐ„์ด 23์‹œ 59๋ถ„ 59์ดˆ๋ฅผ ์ดˆ๊ณผํ•ด์„œ 0์‹œ 0๋ถ„ 0์ดˆ๋กœ ๋Œ์•„๊ฐ€๋Š” ๊ฒฝ์šฐ๋Š” ์ฃผ์–ด์ง€์ง€ ์•Š์Šต๋‹ˆ๋‹ค

๐Ÿ’š ์ž…์ถœ๋ ฅ
h1	m1	s1	h2	m2	s2	result
0	5	30	0	7	0	2
12	0	0	12	0	30	1
0	6	1	0	6	6	0
11	59	30	12	0	0	1
11	58	59	11	59	0	1
1	5	5	1	5	6	2
0	0	0	23	59	59	2852
"""

# h1์‹œ m1๋ถ„ s1์ดˆ๋ถ€ํ„ฐ h2์‹œ m2๋ถ„ s2์ดˆ๊นŒ์ง€ ์•Œ๋žŒ์ด ์šธ๋ฆฌ๋Š” ํšŸ์ˆ˜
def solution(h1, m1, s1, h2, m2, s2):
    answer = 0

    # ์ดˆ๋‹จ์œ„
    start = h1 * 3600 + m1 * 60 + s1
    end = h2 * 3600 + m2 * 60 + s2

    while (start < end) :
        # 1์ดˆ๋‹น!
        # ์‹œ๊ฐ„ : 30๋„/1์‹œ๊ฐ„ = 30๋„/1์‹œ๊ฐ„ * 60๋ถ„ * 60์ดˆ = 30/3600 = 1/120๋„
        # ๋ถ„ : 6๋„/1๋ถ„ = 6๋„/60์ดˆ = 1/10๋„
        # ์ดˆ : 6๋„/1์ดˆ = 6๋„
        hAngle = start / 120 % 360  # 360๋„ ์‹œ๊ณ„์˜ ๊ฐ๋„
        mAngle = start / 10 % 360
        sAngle = start * 6 % 360

        # 0๋„๋กœ ๋‚˜๋‰˜์–ด๋ฒ„๋ฆฌ๊ธฐ ๋•Œ๋ฌธ์—, 360๋„ ํฌํ•จ์‹œ์ผœ์คŒ
        # h) ์ดˆ ์ฆ๊ฐ€
        if ((start + 1) / 120 % 360) == 0 :
            nh = 360
        else :
            nh = (start + 1) / 120 % 360
        # m) ์ดˆ ์ฆ๊ฐ€
        if ((start + 1) / 10 % 360) == 0 :
            nm = 360
        else :
            nm = (start + 1) / 10 % 360
        # s) ์ดˆ ์ฆ๊ฐ€
        if ((start + 1) * 6 % 360) == 0 :
            ns = 360
        else :
            ns = (start + 1) * 6 % 360


        # ์ดˆ์นจ๊ณผ ์‹œ์นจ/๋ถ„์นจ์ด ๊ฒน์น˜๋Š” ํšŸ์ˆ˜
        if hAngle > sAngle and nh <= ns :
            answer += 1
        if mAngle > sAngle and nm <= ns :
            answer += 1
        # ๋‘˜๋‹ค ๊ฒน์น  ๊ฒฝ์šฐ
        if nh == ns and nm == nh :
            answer -= 1

        # ๊ทธ๋‹ค์Œ ์ฆ๊ฐ€
        start += 1

    start = h1 * 3600 + m1 * 60 + s1

    # ์ฒ˜์Œ์— 00์‹œ, 12์‹œ
    if start == 0 or start == 12 * 3600 :
        answer += 1

    return answer

  • ์ •ํ™•์„ฑ

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    
      ์ •ํ™•์„ฑ  ํ…Œ์ŠคํŠธ
      ํ…Œ์ŠคํŠธ 1 ใ€‰	ํ†ต๊ณผ (26.82ms, 10.2MB)
      ํ…Œ์ŠคํŠธ 2 ใ€‰	ํ†ต๊ณผ (37.02ms, 10.3MB)
      ํ…Œ์ŠคํŠธ 3 ใ€‰	ํ†ต๊ณผ (10.72ms, 10.3MB)
      ํ…Œ์ŠคํŠธ 4 ใ€‰	ํ†ต๊ณผ (30.83ms, 10.2MB)
      ํ…Œ์ŠคํŠธ 5 ใ€‰	ํ†ต๊ณผ (0.93ms, 10.1MB)
      ํ…Œ์ŠคํŠธ 6 ใ€‰	ํ†ต๊ณผ (7.90ms, 10.2MB)
      ํ…Œ์ŠคํŠธ 7 ใ€‰	ํ†ต๊ณผ (38.46ms, 10.3MB)
      ํ…Œ์ŠคํŠธ 8 ใ€‰	ํ†ต๊ณผ (38.14ms, 10.1MB)
      ํ…Œ์ŠคํŠธ 9 ใ€‰	ํ†ต๊ณผ (58.74ms, 10.3MB)
      ํ…Œ์ŠคํŠธ 10 ใ€‰	ํ†ต๊ณผ (76.01ms, 10.2MB)
      ํ…Œ์ŠคํŠธ 11 ใ€‰	ํ†ต๊ณผ (41.06ms, 10.3MB)
      ํ…Œ์ŠคํŠธ 12 ใ€‰	ํ†ต๊ณผ (4.16ms, 10.2MB)
      ํ…Œ์ŠคํŠธ 13 ใ€‰	ํ†ต๊ณผ (78.53ms, 10.2MB)
      ํ…Œ์ŠคํŠธ 14 ใ€‰	ํ†ต๊ณผ (54.39ms, 10.1MB)
      ํ…Œ์ŠคํŠธ 15 ใ€‰	ํ†ต๊ณผ (0.02ms, 10.3MB)
      ํ…Œ์ŠคํŠธ 16 ใ€‰	ํ†ต๊ณผ (26.15ms, 10.3MB)
      ํ…Œ์ŠคํŠธ 17 ใ€‰	ํ†ต๊ณผ (31.63ms, 10.4MB)
      ํ…Œ์ŠคํŠธ 18 ใ€‰	ํ†ต๊ณผ (6.18ms, 10MB)
      ํ…Œ์ŠคํŠธ 19 ใ€‰	ํ†ต๊ณผ (88.13ms, 10.3MB)
      ํ…Œ์ŠคํŠธ 20 ใ€‰	ํ†ต๊ณผ (88.74ms, 10.2MB)
      ์ฑ„์  ๊ฒฐ๊ณผ
      ์ •ํ™•์„ฑ: 100.0
      ํ•ฉ๊ณ„: 100.0 / 100.0
    


3. ํ•ด์„ค

  • ๋”ฑ ๊ฐ๋„๊ฐ€ ๋งž๊ฒŒ ๋–จ์–ด์ง€๋Š”๊ฒŒ ์•„๋‹ˆ๋ผ, ์ „ ํ›„์˜ ์ฐจ์ด๋ฅผ ํ†ตํ•ด ๊ฒน์นจ์„ ์นด์šดํŠธ ํ–ˆ๋‹ค
  • 00์‹œ๋ž‘ 12์‹œ์˜ ์˜ˆ์™ธ๋ฅผ ์‹ ๊ฒฝ์จ์ค˜์•ผ ๋ผ์„œ ์ข€ ์–ด๋ ค์› ์Œ
  • ์ฒ˜์Œ ์‹œ์ž‘์˜ ๊ฒน์นจ์„ ์ƒ๊ฐ์„ ๋ชปํ•˜๊ณ  ์žˆ์–ด์„œ ๊ณ ์ƒํ•œ ๋ฌธ์ œ์˜€์Œ
This post is licensed under CC BY 4.0 by the author.