목록알고리즘/문제 (27)
어디까지 갈 수 있을까?
문제링크 programmers.co.kr/learn/courses/30/lessons/17679 1. 전치행렬을 만들어주기 위해 list(map(list, zip(*board))) 1-1. list를 unpacking 하기 위해 * 1-2. zip()은 tuple을 반환하는데 tuple은 값 변경이 안 되니 list로 바꿔줌 1-3. map()은 주소값을 반환하기 때문에 list()로 묶어줌 2. 중복되는 원소를 넣지 않기 위해 set() / set.add() [답코드] import copy def solution(m, n, board): answer = 0 board = list(map(list, zip(*board))) #*는 리스트를 unpacking 한다 while True: remove=set(..
문제링크 programmers.co.kr/learn/courses/30/lessons/17684 [답코드] def solution(msg): answer = [] dict={} for i in range(0, 26): dict[chr(ord('A')+i)]=i+1 i, num=0, 27 w='' while i
문제링크 programmers.co.kr/learn/courses/30/lessons/17683 [답코드] def change(note): note=note.replace('C#','c') note=note.replace('D#','d') note=note.replace('F#','f') note=note.replace('G#','g') note=note.replace('A#','a') return note def solution(m, musicinfos): arr=[] #[제목, 음표] m=change(m) for mm in musicinfos: start, end, title, sound=mm.split(',') sound=change(sound) start_hour, start_min, end_ho..

문제링크 programmers.co.kr/learn/courses/30/lessons/42578 [답코드] def solution(clothes): answer = 1 dict={} for c in clothes: if c[1] not in dict: dict[c[1]]=1 else: dict[c[1]]+=1 for k, v in dict.items(): answer*=(v+1) return answer-1 [풀이법] 해당 예시에서 생성되는 dict는 {'headgear': 2, 'eyewear': 1} 이다. 여기서 headgear를 안 쓰는 경우, 1번 headgear를 쓰는 경우, 2번 headger를 쓰는 경우 3가지가 있다 eyewear를 안 쓰는 경우, 1번 eyewear를 쓰는 경우 2가지가..
문제링크 programmers.co.kr/learn/courses/30/lessons/60059 [답코드] import copy def rotate(key): copy_key=copy.deepcopy(key) for i in range(len(key)): for j in range(len(key)): copy_key[j][-i-1]=key[i][j] return copy_key def check(n, m, copy_lock): for i in range(m, n+m): for j in range(m, n+m): if copy_lock[i][j]!=1: return False return True def add(i, j, copy_lock, key): for k in range(len(key)): for ..

문제링크 www.acmicpc.net/problem/16236 본인보다 크기가 작고 거리가 작으며, 가장 위에 있는 혹은 가장 왼쪽에 있는 물고기를 먹는 문제이다 조건이 많아 까다로웠다 [답코드] 1. 처음 구현 import sys from heapq import heappop, heappush from collections import deque input=sys.stdin.readline def dfs(): # 거리를 알기 위한 완전탐색 m = deque() # 움직일 좌표를 담아두는 m m.append([0, shark[0], shark[1]]) visit = [[False] * n for _ in range(n)] move = [[-1, 0], [1, 0], [0, -1], [0, 1]] visi..

문제링크 www.acmicpc.net/problem/14501 처음에 DFS로 시도했는데 너무 어려워서 DP로 노선 변경하니까 금방 풀렸다,,,ㅎ 현재 일에 도달할 수 있는 날들 중 최대값을 찾아 현재 price+최대 price를 더해가면서 누적하면 풀리는 문제 [답코드] import sys input=sys.stdin.readline n=int(input()) t=[] p=[] for _ in range(n): a, b = map(int, input().split()) t.append(a) p.append(b) # print(t, p) # p에는 선택될 수 있는 값 중 가장 큰 값을 누적시킨다 for i in range(n): max_value=0 for j in range(i): if j+t[j]
문제링크 www.acmicpc.net/problem/1038 ※※답 보기 전에 알고가기※※ n이 1022이면 x가 9876543210이 돼서 n이 1023일 때부터는 감소하는 수가 없게 된다. 이 때 부터는 무조건 -1을 출력하면 된다 시간 복잡도를 최대한 줄였는데 왜 시간초과가 나는지 생각하고 있었는데 이거 때문이었다 [답코드] import sys input=sys.stdin.readline n=int(input()) arr=[i for i in range(10)] i=1 while True: if i>1022: break back=arr[i]%10 for j in range(back): arr.append(arr[i]*10+j) i+=1 arr.sort() # print(arr) if n>len(ar..