본문 바로가기

Coding test

(123)
[백준/20125/파이썬] 쿠키의 신체측정 소스코드 N = int(input()) cookie = [] for _ in range (N): cookie.append(input()) heart = [0,0] body = [0,0,-2,-1,-1] def head(i,j): if cookie[i][j] =='*' and cookie[i][j-1]=='_': heart[0] = i+1 heart[1] = j for i in range(N): for j in range(N): if not heart[0]: head(i,j) #왼팔 if i == heart[0] and cookie[i][j] =="*" and j he..
[백준/14888/파이썬] 연산자 끼워넣기 소스코드 from itertools import permutations N = int(input()) num = list(map(int,input().split())) operator = list(map(int,input().split())) operstr = ['+', '-', '*', '//'] max_ans = -999999999 min_ans = 999999999 # + - * / oplist = [] for i,op in enumerate(operator): for j in range(op): oplist.append(operstr[i]) many = list(permutations(oplist,len(oplist))) def cal(num1,num2, operate): if operate ==..
[백준/12845/파이썬] 모두의 마블 소스코드 N = int(input()) goldlist= list(map(int,input().split())) print(max(goldlist)*(N-2)+sum((goldlist))) 알고리즘 합쳐나가다 보면 가장 큰 수가 계속 더해지는것을 알 수 있다. (N-2번) 그후 전체 리스트의 합을 더하면 된다.
[백준/11047/파이썬] 동전 소스코드 N,K = map(int,input().split()) cnt = 0 coin = [] for i in range(N): money = int(input()) coin.append(money) coin.sort(reverse = True) for i in coin: if K >= (K//i)*i : #큰 수부터 몫연산 2560 // 1000 = 2 -> 2560 - 2000 cnt += K//i #답에 올린 코인 개수 추가 ex) 2개 K = K - (K//i)*i #계산 대상 돈 리셋 print(cnt)
[백준/18290/파이썬] NM과 K (1) 소스코드 def dfs(x, y, d, s): global ans if d == K: ans = max(ans, s) return else: for i in range(x, N): for j in range(y if i == x else 0, M): if [i, j] not in q: if ([i + 1, j] not in q) and ([i - 1, j] not in q) and ([i, j + 1] not in q) and ([i, j - 1] not in q): q.append([i, j]) dfs(i, j, d + 1, s + a[i][j]) q.pop() N, M, K = map(int, input().split()) a = [list(map(int, input().split())) for _ ..
[백준/15655/파이썬] N과 M (6) 소스코드 n,m = list(map(int,input().split())) seq = list(map(int,input().split())) seq = sorted(seq) s = [] def dfs(start): if len(s) == m: print(' '.join(map(str,s))) return for i in seq: if i not in s and (i>=start): s.append(i) dfs(i) s.pop() dfs(1) 알고리즘 N과 M 시리즈 중 하나로 조건을 잘 설정해주면 된다. N과 M (5)에서 변형한 점은 and (i>=start) 이 부분인데 오름차순으로 정렬된 수열에서 앞 순번으로 삽입되는 원소들보다 크다는 조건을 넣어줘야 했다.
[백준/15654/파이썬] N과 M (5) 소스코드 ( itertools 사용 ) from itertools import permutations n,m = list(map(int,input().split())) s = list(map(int,input().split())) tmp = sorted(list(permutations(s,m))) for i in tmp: print(' '.join(map(str,i))) 소스코드 ( 재귀 사용 ) n,m = list(map(int,input().split())) seq = list(map(int,input().split())) seq = sorted(seq) s = [] def dfs(start): if len(s) == m: print(' '.join(map(str,s))) return for i in..
[백준/15652/파이썬] N과 M (4) 소스코드 n,m = list(map(int,input().split())) s = [] def dfs(start): if len(s) == m: print(' '.join(map(str,s))) return for i in range(start,n+1): s.append(i) dfs(i) s.pop() dfs(1) 알고리즘 N과 M 시리즈는 시작점과 세부 조건 사항을 조금씩 바꿔가며 진행하면 되는 것 같다. N과 M (2) 코드와 크게 다르지 않음을 알 수 있다. https://codekunst.tistory.com/49