ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • [๋ฐฑ์ค€] 6603 ๋กœ๋˜ with Python
    PS 2022. 2. 10. 00:10
    728x90
    ๋ฐ˜์‘ํ˜•

    ๐Ÿ“Œ BOJ 6603 ๋กœ๋˜

    ๐Ÿ’ก ์กฐ๊ฑด

    1. ์ง‘ํ•ฉ S์—์„œ K๊ฐœ์˜ ์ˆซ์ž๋ฅผ ๊ณจ๋ผ ๋ฝ‘์•„ ๋‚ผ ์ˆ˜ ์žˆ๋Š” ๊ฒฝ์šฐ์˜ ์ˆ˜๋ฅผ ๋ชจ๋‘ ์ถœ๋ ฅํ•˜๋Š” ๋ฌธ์ œ

    2. ์ž…๋ ฅ์ด ์—ฌ๋Ÿฌ๊ฐœ ๋“ค์–ด์˜ค๋ฉฐ, 0์ด ๋“ค์–ด์™”์„ ๋•Œ ์ข…๋ฃŒ

    3. ๋ฐฑํŠธ๋ž˜ํ‚น, ์žฌ๊ท€, ์กฐํ•ฉ์œ ํ˜•์˜ ๋ฌธ์ œ

    ๐Ÿ–ฅ ์†Œ์Šค ์ฝ”๋“œ

    from sys import stdin
    from itertools import combinations
    
    while 1:
        data = list(map(int, stdin.readline().split()))
        if len(data) == 1 and data[0] == 0:
            break
        else:
            a, arr = data[0], data[1:]
            res = []
            for x in list(set(combinations(arr, 6))):
                if len(set(x)) == 6:
                    temp = sorted(list(x))
                    if temp not in res:
                        res.append(temp)
    
        for x in sorted(list(res)):
            print(*x)
        print()

    ๐Ÿ”– ์˜ˆ์ œ ๋ฐ ์‹คํ–‰๊ฒฐ๊ณผ

    ์˜ˆ์ œ

    7 1 2 3 4 5 6 7
    8 1 2 3 5 8 13 21 34
    0

    ์‹คํ–‰๊ฒฐ๊ณผ

    1 2 3 4 5 6
    1 2 3 4 5 7
    1 2 3 4 6 7
    1 2 3 5 6 7
    1 2 4 5 6 7
    1 3 4 5 6 7
    2 3 4 5 6 7
    
    1 2 3 5 8 13
    1 2 3 5 8 21
    1 2 3 5 8 34
    1 2 3 5 13 21
    1 2 3 5 13 34
    1 2 3 5 21 34
    1 2 3 8 13 21
    1 2 3 8 13 34
    1 2 3 8 21 34
    1 2 3 13 21 34
    1 2 5 8 13 21
    1 2 5 8 13 34
    1 2 5 8 21 34
    1 2 5 13 21 34
    1 2 8 13 21 34
    1 3 5 8 13 21
    1 3 5 8 13 34
    1 3 5 8 21 34
    1 3 5 13 21 34
    1 3 8 13 21 34
    1 5 8 13 21 34
    2 3 5 8 13 21
    2 3 5 8 13 34
    2 3 5 8 21 34
    2 3 5 13 21 34
    2 3 8 13 21 34
    2 5 8 13 21 34
    3 5 8 13 21 34

    โŒจ๏ธ ๋ฌธ์ œ ํ’€์ด

    1. ์กฐํ•ฉ์„ ์ด์šฉํ•˜์—ฌ S ์ˆ˜์—ด์— ์žˆ๋Š” K๊ฐœ์˜ ์ˆซ์ž๋ฅผ ๋ฝ‘์•„๋‚ธ ์กฐํ•ฉ์˜ ๊ฒฝ์šฐ์˜ ์ˆ˜๋ฅผ ๊ตฌํ•˜๋˜, ๊ฐ€๋Šฅํ•œ ์กฐํ•ฉ์„ ๋ชจ๋‘ ์ถœ๋ ฅํ•˜๋Š” ๋ฌธ์ œ.

    2. combinations ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์กฐํ•ฉ์„ ๋ชจ๋‘ ๋ฝ‘์•„๋‚ด๊ณ , res ๋ผ๋Š” ๋ฆฌ์ŠคํŠธ์— ๋„ฃ์–ด ์ถœ๋ ฅํ–ˆ๋‹ค.

    ๐Ÿ’พ ๋Š๋‚€์ 

    1. ๋ฐฑํŠธ๋ž˜ํ‚น ๋ฌธ์ œ๋Š” ์žฌ๊ท€๋กœ ํ’€์–ด๋ณด๋Š” ๊ฒƒ์ด ๋„์›€์ด ๋œ๋‹ค.
    2. N๊ณผ M ์‹œ๋ฆฌ์ฆˆ๋ฅผ ํ’€๋ฉด์„œ ์žฌ๊ท€๋กœ ๋ฐฑํŠธ๋ž˜ํ‚น์„ ์—ฐ์Šตํ•˜๋Š” ๊ฒƒ๋„ ์ข‹์„ ๊ฒƒ ๊ฐ™๋‹ค.
    ๋ฐ˜์‘ํ˜•

    ๋Œ“๊ธ€

Designed by Tistory.