<문제>

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

 

 

<풀이>

import sys
from collections import deque
input = sys.stdin.readline

T = int(input())
games = []

for _ in range(T):
    input()
    N, M = input().split()
    
    S = deque(sorted(list(map(int, input().split()))))
    B = deque(sorted(list(map(int, input().split()))))
    temp_arr = [S, B]

    games.append(temp_arr)

for arrs in games:
    S, B = arrs

    while len(S) > 0 and len(B) > 0:
        s, b = S[0], B[0]

        if s > b:
            B.popleft()
        elif s < b:
            S.popleft()
        else:
            B.popleft()
        
    if len(S) == 0 and len(B) == 0: print('C')
    elif len(S) == 0: print('B')
    elif len(B) == 0: print('S')

 

- 차례로 비교해야 한다는 생각에 너무 어렵게 풀었음

- 작은 수가 먼저 조회되어야 하기 때문에 sort

- 시간 복잡도를 위해 deque

- 작은 것끼리 하나씩 비교해서 각각 프린트

 

 

<다른 풀이>

import sys

input = sys.stdin.readline

def solution():
    T = int(input())
    for _ in range(T):
        input()
        input()
        s = max(map(int, input().split()))
        b = max(map(int, input().split()))
        print('B' if b > s else 'S')

solution()

 

- 어차피 큰 숫자가 계속 이기게 되어있고 상대방의 그 다음 작은 수와 비교해도 마찬가지 결과

- 결국 가장 큰 수를 가지고 있는 사람이 이기는 게임

- 문제에서 친절하게 경우의 수까지 좁혀줬음 (b>s 아니면 모두 S)

'TIL > [파이썬] 1일 1코테' 카테고리의 다른 글

열심히 일하는 중_백준31860  (0) 2025.02.23
개미_백준3048  (0) 2025.02.20
[정렬] 좌표압축_백준18870  (0) 2025.02.18
[정렬] H-Index_프로그래머스  (0) 2025.02.17
파일 정리_백준20291  (0) 2025.02.17

+ Recent posts