Post

๐Ÿน ์•„๋‚ ๋กœ๊ทธ ์‹œ๊ณ„

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

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


2. ์ฝ”๋“œ

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# ๋ถ„์นจ๊ณผ ์ดˆ์นจ์ด ๋งŒ๋‚˜๋Š” ๋ชจ๋“  ๊ฒฝ์šฐ(๋ถ„๋‹จ์œ„)
minute_hand = [(6 * i / (6 - 0.1)) for i in range(1440)]
# ์‹œ์นจ๊ณผ ์ดˆ์นจ์ด ๋งŒ๋‚˜๋Š” ๋ชจ๋“  ๊ฒฝ์šฐ(๋ถ„๋‹จ์œ„)
hour_hand = [(6 * i / (6 - 30/3600)) for i in range(1440)]

def solution(h1, m1, s1, h2, m2, s2):
    start = h1 * 60 + m1 + s1 / 60
    end = h2 * 60 + m2 + s2 / 60
    print(start, end)
    time_to_meet = []
    for i in range(1440):
        if start <= hour_hand[i] <= end and hour_hand[i] not in time_to_meet:
            time_to_meet.append(hour_hand[i])
        if start <= minute_hand[i] <= end and minute_hand[i] not in time_to_meet:
            time_to_meet.append(minute_hand[i])
    return len(time_to_meet)

  • ํ…Œ์ŠคํŠธ ๊ฒฐ๊ณผ

    ํ…Œ์ŠคํŠธ 1 ใ€‰ํ†ต๊ณผ (3.64ms, 10.4MB)
    ํ…Œ์ŠคํŠธ 2 ใ€‰ํ†ต๊ณผ (10.06ms, 10.3MB)
    ํ…Œ์ŠคํŠธ 3 ใ€‰ํ†ต๊ณผ (0.92ms, 10.4MB)
    ํ…Œ์ŠคํŠธ 4 ใ€‰ํ†ต๊ณผ (11.92ms, 10.5MB)
    ํ…Œ์ŠคํŠธ 5 ใ€‰ํ†ต๊ณผ (0.21ms, 10.3MB)
    ํ…Œ์ŠคํŠธ 6 ใ€‰ํ†ต๊ณผ (1.30ms, 10.4MB)
    ํ…Œ์ŠคํŠธ 7 ใ€‰ํ†ต๊ณผ (18.48ms, 10.2MB)
    ํ…Œ์ŠคํŠธ 8 ใ€‰ํ†ต๊ณผ (9.19ms, 10.3MB)
    ํ…Œ์ŠคํŠธ 9 ใ€‰ํ†ต๊ณผ (15.31ms, 10.1MB)
    ํ…Œ์ŠคํŠธ 10 ใ€‰ํ†ต๊ณผ (17.43ms, 10.2MB)
    ํ…Œ์ŠคํŠธ 11 ใ€‰ํ†ต๊ณผ (4.59ms, 10.2MB)
    ํ…Œ์ŠคํŠธ 12 ใ€‰ํ†ต๊ณผ (0.58ms, 10.3MB)
    ํ…Œ์ŠคํŠธ 13 ใ€‰ํ†ต๊ณผ (32.16ms, 10.3MB)
    ํ…Œ์ŠคํŠธ 14 ใ€‰ํ†ต๊ณผ (11.93ms, 10.3MB)
    ํ…Œ์ŠคํŠธ 15 ใ€‰ํ†ต๊ณผ (0.39ms, 10.3MB)
    ํ…Œ์ŠคํŠธ 16 ใ€‰ํ†ต๊ณผ (4.08ms, 10.3MB)
    ํ…Œ์ŠคํŠธ 17 ใ€‰ํ†ต๊ณผ (8.91ms, 10.3MB)
    ํ…Œ์ŠคํŠธ 18 ใ€‰ํ†ต๊ณผ (0.43ms, 10.2MB)
    ํ…Œ์ŠคํŠธ 19 ใ€‰ํ†ต๊ณผ (67.18ms, 10.3MB)
    ํ…Œ์ŠคํŠธ 20 ใ€‰ํ†ต๊ณผ (52.37ms, 10.2MB)


3. ํ•ด์„ค

๋ถ„์นจ๊ณผ ์ดˆ์นจ์ด 24์‹œ๊ฐ„ ๋‚ด์— ๋งŒ๋‚˜๋Š” ๋ชจ๋“  ๊ฒฝ์šฐ๋ฅผ minute_hand์—, ์‹œ์นจ๊ณผ ์ดˆ์นจ์ด 24์‹œ๊ฐ„ ๋‚ด์— ๋งŒ๋‚˜๋Š” ๋ชจ๋“  ๊ฒฝ์šฐ๋ฅผ hour_hand์— ์ดˆ๊ธฐํ™”ํ•œ๋‹ค. ์ด๋•Œ ๋ถ„ ๋‹จ์œ„๋กœ (1440๋ถ„) ๊ณ„์‚ฐํ•œ๋‹ค.

์ฃผ์–ด์ง„ ์‹œ๊ฐ„์„ ๋ถ„ ๋‹จ์œ„๋กœ ๋ณ€๊ฒฝํ•˜๊ณ  ์‹œ์ž‘ ์‹œ๊ฐ„๊ณผ ๋๋‚˜๋Š” ์‹œ๊ฐ„ ์‚ฌ์ด์— ๋“ค์–ด์˜ค๋Š” ๋งŒ๋‚˜๋Š” ๊ฒฝ์šฐ๋ฅผ ๋ชจ๋‘ ์„ธ์ค€๋‹ค. ์ด

๋•Œ ๋ถ„์นจ, ์‹œ์นจ, ์ดˆ์นจ์ด ํ•œ ๋ฒˆ์— ๋งŒ๋‚˜๋Š” ๊ฒฝ์šฐ๊ฐ€ ์žˆ์œผ๋ฏ€๋กœ, ์‹œ์นจ-์ดˆ์นจ ๋งŒ๋‚˜๋Š” ์‹œ๊ฐ„, ๋ถ„์นจ-์ดˆ์นจ ๋งŒ๋‚˜๋Š” ์‹œ๊ฐ„์„ time_to_meet ๋ฆฌ์ŠคํŠธ์— ๋„ฃ์–ด์ฃผ๊ณ  ํ•ด๋‹น ๋ฆฌ์ŠคํŠธ์— ์ด๋ฏธ ๊ฐ’์ด ์กด์žฌํ•˜๋Š” ๊ฒฝ์šฐ์—๋Š” ๋ฌด์‹œํ•œ๋‹ค.

์ตœ์ข…์ ์œผ๋กœ time_to_meet ๋ฆฌ์ŠคํŠธ์˜ ๊ธธ์ด๋ฅผ ๋ฆฌํ„ดํ•œ๋‹ค.

This post is licensed under CC BY 4.0 by the author.