Koala - 17기/코딩테스트 기초 스터디

[백준/Python] #4435 중간계 전쟁

chxx1902 2025. 1. 12. 23:16

4435번: 중간계 전쟁

알고리즘:

DFS(깊이 우선 탐색)를 활용하여 백트래킹으로 문제를 해결한다. 이를 통해 각 전투의 결과를 저장하고 출력하도록 구현하였다.

코드:

G_S = [1, 2, 3, 3, 4, 10]  
S_S = [1, 2, 2, 2, 3, 5, 10] 

def cbr(g_c, s_c):
    g_t = sum(g_c[i] * G_S[i] for i in range(len(G_S)))
    s_t = sum(s_c[i] * S_S[i] for i in range(len(S_S)))

    # 결과 비교
    if g_t > s_t:
        return "Good triumphs over Evil"
    elif g_t < s_t:
        return "Evil eradicates all trace of Good"
    else:
        return "No victor on this battle field"

def main():
    T = int(input())  
    results = []

    for b_num in range(1, T + 1):
        g_c = list(map(int, input().split()))
        s_c = list(map(int, input().split()))

        # 결과 계산
        result = cbr(g_c, s_c)
        results.append(f"Battle {b_n}: {result}")

    # 결과 출력
    for result in results:
        print(result)

if __name__ == "__main__":
    main()