From 73bfa6e02ea4b56cc2a886d0c5b74cb7af066c96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8C=E1=85=A1=E1=86=BC=E1=84=83=E1=85=A9=E1=86=BC?= =?UTF-8?q?=E1=84=89=E1=85=AE?= Date: Fri, 15 Jul 2022 16:54:29 +0900 Subject: [PATCH] =?UTF-8?q?Solve=20#7=20:=20=EC=97=B0=EC=82=B0=EC=9E=90=20?= =?UTF-8?q?=EB=81=BC=EC=9B=8C=EB=84=A3=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Solving/WEEK1/TEAM1/14888/dongsoo.py | 55 ++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 Solving/WEEK1/TEAM1/14888/dongsoo.py diff --git a/Solving/WEEK1/TEAM1/14888/dongsoo.py b/Solving/WEEK1/TEAM1/14888/dongsoo.py new file mode 100644 index 0000000..9b5cfd8 --- /dev/null +++ b/Solving/WEEK1/TEAM1/14888/dongsoo.py @@ -0,0 +1,55 @@ +import sys +from collections import deque +input=sys.stdin.readline + +# N 값 +n=int(input()) +# 숫자 +number_list=list(map(int,input().split())) +# 연산자 +operator_list=list(map(int,input().split())) + +#시작점 +start=number_list[0] + +#연산 완료된 리스트 넣기 +answer=[] + +#백트래킹 사용하여 모든 수식 풀기 +#numList= 숫자 리스트 operList= 연산자 리스트 count = 연산 횟수 k= count 만큼 연산 했을때의 수 +def solve(numList,operList,k,count): + if count!=n-1: + num=numList[count+1] + for i in range(4): + if operList[i]!=0: + operList[i]-=1 + count+=1 + if i==0: + solve(numList,operList,k+num,count) + elif i==1: + solve(numList,operList,k-num,count) + elif i==2: + solve(numList,operList,k*num,count) + elif i==3: + temp=0 + # 음수일경우 양수로 변환후 몫 구하고 음수로 바꾸고 넣기 + if k<0: + temp=-k + temp=temp//num + temp=-temp + else: + temp=k//num + solve(numList,operList,temp,count) + #백트래킹 + count-=1 + operList[i]+=1 + + # 연산을 모두 했을 경우 + elif count==(n-1): + answer.append(k) + return + + +solve(number_list,operator_list,start,0) +print(max(answer)) +print(min(answer)) \ No newline at end of file