๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

๐Ÿ’ปAlgorithm/PS

[BOJ/๋ฐฑ์ค€] 2160 ๊ทธ๋ฆผ๋น„๊ต - ํŒŒ์ด์ฌ

๋ฌธ์ œ

https://www.acmicpc.net/problem/2160

 

2160๋ฒˆ: ๊ทธ๋ฆผ ๋น„๊ต

N(2 ≤ N ≤ 50)๊ฐœ์˜ ๊ทธ๋ฆผ์ด ์žˆ๋‹ค. ๊ฐ๊ฐ์˜ ๊ทธ๋ฆผ์€ 5×7์˜ ํฌ๊ธฐ์ด๊ณ , ๋‘ ๊ฐ€์ง€ ์ƒ‰์œผ๋กœ ๋˜์–ด ์žˆ๋‹ค. ์ด๋•Œ ๋‘ ๊ฐ€์ง€์˜ ์ƒ‰์„ ๊ฐ๊ฐ ‘X’์™€ ‘.’์œผ๋กœ ํ‘œํ˜„ํ•˜๊ธฐ๋กœ ํ•˜์ž. ์ด๋Ÿฌํ•œ ๊ทธ๋ฆผ๋“ค์ด ์ฃผ์–ด์กŒ์„ ๋•Œ, ๊ฐ€์žฅ ๋น„

www.acmicpc.net

 

 

๋ฌธ์ œํ’€์ด

๊ฐ„๋‹จํ•œ bruteforce ๋ฌธ์ œ์ด๋‹ค.

์ž…๋ ฅ๋ฐ›์€ ๊ทธ๋ฆผ์„ ํ•˜๋‚˜์”ฉ ๋น„๊ตํ•ด์„œ ๊ฐ ์›์†Œ๊ฐ€ ๊ฐ™์€ ๊ฐ’์ธ์ง€ ์•„๋‹Œ์ง€ ํ™•์ธํ•œ๋‹ค.

๊ฐ€์žฅ ๋น„์Šทํ•œ ๋‘ ๊ทธ๋ฆผ(๊ฐ’์ด ๋‹ค๋ฅธ ์›์†Œ๊ฐ€ ์ตœ์†Œ์ธ ๊ทธ๋ฆผ ๋‘๊ฐ€์ง€)์˜ ๋ฒˆํ˜ธ๋ฅผ ์ถœ๋ ฅํ•œ๋‹ค.

 

 

์ฝ”๋“œ

import sys
input=sys.stdin.readline

n=int(input())
pic=[]
for i in range(n):
    pic.append(list([input().rstrip() for _ in range(5)]))

a=[]
for i in range(n-1):
    for j in range(i+1,n):
        temp=0
        for k in range(5):
            for l in range(7):
                if pic[i][k][l]!=pic[j][k][l]:
                    temp+=1
        a.append((temp,i+1,j+1))

result=min(a)
print(result[1],result[2])