본문 바로가기

알고리즘 테스트/완전 탐색

baseball game

입력


첫째 줄에는 민혁이가 영수에게 몇 번이나 질문을 했는지를 나타내는 1 이상 100 이하의 자연수 N이 주어진다. 이어지는 N개의 줄에는 각 줄마다 민혁이가 질문한 세 자리 수와 영수가 답한 스트라이크 개수를 나타내는 정수와 볼의 개수를 나타내는 정수, 이렇게 총 세 개의 정수가 빈칸을 사이에 두고 주어진다.

 

출력


첫 줄에 영수가 생각하고 있을 가능성이 있는 답의 총 개수를 출력한다.

 

예제 입력

4

123 1 1

356 1 0

327 2 0

489 0 1

예제 출력

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
= int(input())
arr = [[0]*3 for _ in range(n)]
possible = []
result = []
 
for i in range(n):
    arr[i] = list(map(int, input().split()))
 
for j in range(1001000):
    digit = str(j)
    if digit[0!= digit[1and digit[1!= digit[2and digit[0!= digit[2and '0' not in digit:
        possible.append(digit)
        result.append(digit)
 
for i in range(len(arr)):
    strike = arr[i][1]
    ball = arr[i][2]
 
    num = str(arr[i][0])
    first = num[0]
    second = num[1]
    third = num[2]
 
    for j in range(len(possible)):
        strike_cnt = 0
        ball_cnt = 0
        if str(possible[j][0]) == first:
            strike_cnt += 1
        elif str(possible[j][0]) in num:
            ball_cnt += 1
 
        if str(possible[j][1]) == second:
            strike_cnt += 1
        elif str(possible[j][1]) in num:
            ball_cnt += 1
 
        if str(possible[j][2]) == third:
            strike_cnt += 1
        elif str(possible[j][2]) in num:
            ball_cnt += 1
 
        if strike != strike_cnt or ball != ball_cnt:
            try:
                re_val = possible[j]
                result.remove(re_val)
            except:
                continue
print(len(result))
cs

'알고리즘 테스트 > 완전 탐색' 카테고리의 다른 글

seat  (2) 2021.07.25
tetris  (0) 2021.07.25
bingo  (0) 2021.07.25
attack range  (0) 2021.07.25
rook  (0) 2021.07.25