
SWEA 2819 격자판의 숫자 이어 붙이기 (파이썬)
2022. 9. 23. 14:06
SWEA
https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV7I5fgqEogDFAXB SW Expert Academy SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요! swexpertacademy.com 풀이 sys.setrecursionlimit(1000000) # 상하좌우로 갈 수 있는 모든 경로를 6번 이동 def dfs(depth, r, c, str): # 6번 갔으면, str을 set에 넣어주고 return if depth == 6: result.add(str) return for di, dj in [[1, 0], [0, 1], [-1, 0], [0, -1]]: nr, nc = r + di..

SWEA 1486 장훈이의 높은 선반 (파이썬)
2022. 9. 23. 13:09
SWEA
https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV2b7Yf6ABcBBASw SW Expert Academy SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요! swexpertacademy.com 아이디어 간단한 문제이다. 모든 직원들의 키를 더한 순열을 만들어 그 중 B이상인 것 중 가장 작은 값을 출력한다. 풀이 for tc in range(int(input())): N, B = map(int, input().split()) H = list(map(int, input().split())) # 모든 탑의 길이를 담을 리스트 sums_lst = [0] for i in range(N): # 현..

SWEA 4366 정식이의 은행업무 (파이썬)
2022. 9. 23. 11:48
SWEA
https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AWMeRLz6kC0DFAXd SW Expert Academy SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요! swexpertacademy.com 아이디어 입력 받은 2진수를 하나의 원소를 바꿔 10진수로 변환하여 set에 집에 넣는다. 예를 들어 1010이면 처음엔 1을 0으로 바꿔 0010을 10진수로 바꿔 set에 넣는다. 같은 방식으로 3진수를 요소가 0이면 1, 2로 바꾸고 10진수로 만들어준다. 3진수에서 바꾼 10진수가 set안에 있다면 출력하고 종료한다. 풀이 def solve(): tmp = '012' for k in rang..

백준 1918 후위 표기식 (파이썬)
2022. 9. 20. 22:01
백준
풀이 및 해설(주석) def isp(s): if s == '*' or s == '/': return 2 elif s == '(': return 0 else: return 1 def icp(s): if s == '*' or s == '/': return 2 elif s == '(': return 3 else: return 1 def cal_1(lst): # 후위 표기식으로 변환하는 함수 stack = [] for i in lst: if i.isalpha(): # 숫자인 경우 빈 리스트에 넣어준다. result_1.append(i) elif i == '(': # 여는 괄호일 경우 무조건 스택에 넣어준다. stack.append(i) elif i == ')': # 닫는 괄호가 나오면 여는 괄호가 나올 때 까지..

백준 3980 선발 명단 백트래킹 (파이썬)
2022. 9. 20. 21:43
백준
풀이 주석참조 def solve(depth): global result # depth를 포지션으로 정의 depth가 11이 되면, 포지션이 꽉 찬 상태 if depth == 11: # 지금까지 넣어논 선수의 능력치를 모두 더한값을 정해주고 return result = max(result, sum(ans)) return # 여기서 사용하는 i는 배열의 열, 행은 depth로 정의 즉, 배열의 열이 하나 있다면, 다른 행의 요소는 열 번호가 달라야함 for i in range(11): if visited[i]: continue # 0이 아니라면 if skill[depth][i]: visited[i] = 1 ans.append(skill[depth][i]) solve(depth+1) # 마지막 원소를 pop하..

itertools 순열과 조합 라이브러리 (파이썬)
2022. 9. 19. 19:15
카테고리 없음
순열 permutations(반복 가능한 객체, n) // n은 몇 개 뽑을지 중복 허용하지 않음 순서에 의미가 없음 from itertools import permutations print(list(permutations([1,2,3,4], 2))) # [(1, 2), (1, 3), (1, 4), (2, 1), (2, 3), (2, 4), (3, 1), (3, 2), (3, 4), (4, 1), (4, 2), (4, 3)] 중복 순열 product(반복 가능한 객체, n) // n은 몇 개 뽑을지 중복 허용 from itertools import product print(list(product([1,2,3,4], repeat=2))) # [(1, 1), (1, 2), (1, 3), (1, 4), (2,..

백준 5427 불 (파이썬)
2022. 9. 18. 14:53
백준
풀이 from collections import deque # 불이 퍼지는 함수 시간 단위로 한번만 실행됨 def bfs1(): for _ in range(len(Q_f)): r, c = Q_f.popleft() for di, dj in [[1, 0], [0, 1], [-1, 0], [0, -1]]: nr, nc = r + di, c + dj if 0

백준 N과 M 3~12 (파이썬)
2022. 9. 17. 18:35
백준
N과 M (3) 코드 import sys def solve(depth, N, M): # depth가 M과 같아질 때 리턴 if depth == M: print(*ans) return for i in range(1, N+1): # if visited[i]: # continue # visited[i] = 1 ans.append(i) solve(depth+1, N, M) # 리턴 후 실행될 코드 # for문이 끝나도 실행이 된다. ans.pop() visited[i] = 0 N, M = map(int, sys.stdin.readline().split()) arr = [] for i in range(1, N+1): arr.append(i) visited = [0] * (N+1) ans = [] solve(0, ..