import numpy as np
from scipy.optimize import linprog
import re

# 제작자 : 태양
# 수정자 : hopper
# 입력 방식 개선: 한 번에 모든 데이터를 받아서 처리

# https://[Log in to view URL]

input_lines = []
for _ in range(50):
    try:
        line = input()
        input_lines.append(line)
    except EOFError:
        input_lines.append("")  # 입력이 끊기면 빈 문자열 추가
    except KeyboardInterrupt:
        input_lines.append("")  # Ctrl+C 같은 경우도 빈 문자열로 처리

# 입력 데이터를 한 줄로 합치고 모든 공백과 줄바꿈 제거
input_data = "".join(input_lines).replace(" ", "").replace("\n", "")

# 괄호 안의 숫자 추출을 위한 정규식 패턴
pattern = r'\((\d+)\)'
matches = re.findall(pattern, input_data)

# 추출된 숫자들을 정수로 변환하여 current_stats 리스트에 저장
current_stats = [int(match) for match in matches]

# 6개의 스탯이 모두 입력되었는지 확인
if len(current_stats) < 6:
    print(f"주의: {len(current_stats)}개의 능력치만 인식되었습니다. 6개가 필요합니다.")
    # 부족한 경우 0으로 채움
    current_stats.extend([0] * (6 - len(current_stats)))
elif len(current_stats) > 6:
    print(f"주의: {len(current_stats)}개의 능력치가 인식되었습니다. 처음 6개만 사용합니다.")
    current_stats = current_stats[:6]

# 능력치 순서: 힘, 생명, 지력, 정신, 행운, 속도
print("입력받은 데이터: 힘, 생명, 지력, 정신, 행운, 속도")
print(current_stats, "\n")

def optimize_levelups_improved(current_stats):
    # 각 직업별 능력치 증가량 (행: 직업, 열: 스탯)
    stat_gains = np.array([
        [2, 1, 0, 0, 1, 0],  # 검술
        [0, 0, 1, 0, 1, 2],  # 인술
        [0, 1, 1, 2, 0, 0],  # 신술
        [0, 0, 2, 1, 0, 1],  # 마술
        [1, 0, 0, 0, 2, 1],  # 궁술
        [1, 2, 0, 1, 0, 0]   # 체술
    ])
    
    # 각 능력치별 목표 한계치 설정 (힘, 생명, 지력, 정신, 행운, 속도 순)
    min_stats = [401, 401, 401, 401, 401, 401]  # 모든 능력치가 401 이상이 되도록 설정
    required_stats = np.array(min_stats) - np.array(current_stats)
    
    # 선형 계획법 설정 - 부등호 제약조건 (A_ub * x >= b_ub를 -A_ub * x <= -b_ub 형태로 변환)
    c = np.ones(6)  # 최소화할 목표 (총 레벨업 횟수)
    
    # 모든 스탯이 최소 기준치를 넘도록 제약
    A_ub = -stat_gains.T  # 음수를 취해 ≥ 제약조건으로 변환
    b_ub = -required_stats  # 음수를 취해 ≥ 제약조건으로 변환
    
    # 경계 조건: 각 직업의 레벨업 횟수는 0 이상
    bounds = [(0, None)] * 6
    
    # 선형 계획법 실행
    res = linprog(c, A_ub=A_ub, b_ub=b_ub, bounds=bounds, method='highs')
    
    if res.success:
        # 소수점 처리를 위해 올림 (최소 조건을 충족하기 위해)
        job_levelups = [int(np.ceil(x)) for x in res.x]
        
        # 결과 출력
        result = {"검술": job_levelups[0], "체술": job_levelups[5], "마술": job_levelups[3],
                  "신술": job_levelups[2], "궁술": job_levelups[4], "인술": job_levelups[1]}
        
        # 최종 결과 능력치 계산
        final_stats = np.array(current_stats) + np.dot(job_levelups, stat_gains)
        
        print("== 직업별 능력치업 횟수 ==")
        for job, levelups in result.items():
            print(f"{job} : {levelups} 번")
        
        print("\n== 총 능력치업 횟수 ==")
        print(f"총 {sum(job_levelups)} 번")
        
        print("\n== 최종 능력치 ==")
        stat_names = ["힘", "생명", "지력", "정신", "행운", "속도"]
        for i, (name, value, target) in enumerate(zip(stat_names, final_stats, min_stats)):
            print(f"{name}: {value} (목표: {target}, 차이: {value - target})")
        
        # 최소 기준치를 충족하는지 확인
        all_satisfied = all(final_stats >= min_stats)
        if all_satisfied:
            print("\n모든 능력치가 401 이상으로 목표를 달성했습니다.")
        else:
            print("\n경고: 일부 능력치가 목표치에 도달하지 못했습니다.")
            
    else:
        print("해결 불가능한 상태입니다.")
        print("오류:", res.message)

# 함수 실행
optimize_levelups_improved(current_stats)

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: