문제:
풀이 방법:
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 | def generator(N,n): answer = [N] if n==1: return answer for i in range(2,n+1): temporary=[] for j in answer: temporary.append(j+N) if abs(j-N)!=0: temporary.append(abs(j-N)) a,b=max(j,N),min(j,N) temporary.append(a//b) temporary.append(j*N) answer+=temporary answer.append(int(str(N)*i)) return answer def solution(N, number): answer= [9] if N==number: return 1 for i in range(1,8): if number in generator(N,i): answer.append(i) for i in range(2,5): answer1=generator(N,i) for j in range(i,9-i): answer2=generator(N,j) if min(answer)<i+j: pass else: temporary=[] for l in answer2: for k in answer1: temporary.append(k+l) temporary.append(abs(k-l)) c,d=max(l,k),min(l,k) if d!=0: temporary.append(c//d) temporary.append(l*k) if number in temporary: answer.append(i+j) if answer==[9]: return -1 else: return min(answer) return min(answer) | cs |
'Algorithm > Python' 카테고리의 다른 글
[Programmers]Lv 3. 2 X N 타일링 (0) | 2019.02.21 |
---|---|
[Programmers]Lv 2. 위장 (0) | 2019.02.20 |
[Programmers]Lv 2. H-Index (0) | 2019.02.18 |
[Programmers]Lv 2.전화번호 목록 (0) | 2019.02.16 |
[Programmers]Lv 1.모의고사 (0) | 2019.02.15 |