알고리즘/알고리즘_swea 41

[Python][SWEA] 1240. [S/W 문제해결 응용] 1일차 - 단순 2진 암호코드 D3

SW Expert AcademySW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!swexpertacademy.com🗒️ 파이썬 코드 풀이#--------------------------------------------------------# 아이디어 정리# 0. 2진 코드 딕셔너리 형태로 생성# 1. 행의 합이 0인것 제외하고 0이 아닌 첫 행 추출 (for-if)# 2. 뒤에서 부터 1이 나오는 인덱스 위치부터 -56개까지 추출 (for)# 3. 56비트를 7비트씩 8개로 쪼개고, 딕셔너리에서 value값 추출 (for)# 4. 올바른 코드인지 체크 (for)#--------------------------------------------------------# 시간 복잡도 #..

[Python][SWEA] 1493. 수의 새로운 연산 D3

SW Expert AcademySW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!swexpertacademy.com🗒️ 파이썬 코드 풀이i = j = 1dic = {(i,j) : 1} # 인덱스 위치 -> 좌표값u_dic = {1 : (i,j)} # 좌표값 -> 인덱스 위치for n in range(2,50000) : # 인덱스 위치,좌표값 딕셔너리 형태로 생성 i -= 1 j += 1 if i == 0 : i = j j = 1 dic[(i,j)] = n u_dic[n] = (i,j)T = int(input())for tc in range(1,T+1) : p,q = list(map(int,input(..

[Python][SWEA] 1946. 간단한 압축 풀기 D2

SW Expert AcademySW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!swexpertacademy.com🗒️파이썬 코드 풀이T = int(input())for tc in range(1,T+1) : N = int(input()) lst = [(input().split()) for _ in range(N)] # 입력 받기 for i in range(N) : # 숫자형으로 변환 lst[i][1] = int(lst[i][1]) sentence = "" for char,num in lst : # 문자 * 숫자로 문자열 만들고 합치기 sentence += char * num print(f"#{tc}") # 너비..

[Python][SWEA] 4615. 재미있는 오셀로 게임 D3

SW Expert AcademySW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!swexpertacademy.com🗒️파이썬 코드 풀이T = int(input())for tc in range(1,T+1) : N,M = map(int,input().split()) lst = [list(map(int,input().split())) for _ in range(M)] # 오셀로 기본 세팅 othello = [[0] * (N+1) for _ in range(N+1)] center = N//2 othello[center][center] = othello[center+1][center+1] = 2 othello[center+1][center] = oth..

[Python][SWEA] S/W 문제해결 기본 3일차 - 회문2 D3

SW Expert AcademySW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!swexpertacademy.com🗒️파이썬 코드 풀이for tc in range(1,11) : T = int(input()) lst = [] lst = [list(input()) for _ in range(100)] lst_v = [] # 세로->가로 전환 리스트 for j in range(100): tmp = [] for i in range(100): tmp.append(lst[i][j]) lst_v.append(tmp) mx = 1 for i in range(100) : # 1~100개 ..

[Python][SWEA] 1860. 진기의 최고급 붕어빵 D3

SW Expert AcademySW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!swexpertacademy.com 🗒️파이썬 코드 풀이T = int(input())for tc in range(1,T+1) : N,M,K = map(int,input().split()) lst = list(map(int,input().split())) ans = "Possible" lst.sort() cnt = 0 for t in lst : cnt += 1 if (t//M)*K  1. 기본값은 Possible로 한다 2. 크기순으로 sort 정렬을 해준다. (먼저 오는 손님에게 붕어빵 먼저 제공) 3. 손님들의 도착시간 리스트..

[Python][SWEA] 1249. [S/W 문제해결 응용] 4일차 - 보급로 D4

SW Expert AcademySW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!swexpertacademy.com🗝️ DFS / BFS 와 STACK / QUEUE1. DFS- 스택,재귀 함수를 이용해서 구현 (일반적으로 재귀함수 사용)- 노드를 인접 노드가 없을때까지 스택에 넣음- 방문 처리가 완료되면 스택에서 최상단 노드를 꺼냄  1. BFS- 그래프에 가까운 노드부터 우선 탐색- 큐(Queue) 자료구조 사용  🗒️파이썬 코드 풀이from collections import dequeT = int(input())for tc in range(1,T+1): N = int(input()) lst = [] lst = [list(map(int,input())) fo..

[Python][SWEA] 2814. 최장 경로 D3

SW Expert AcademySW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!swexpertacademy.com 🗒️파이썬 코드 풀이T = int(input())for tc in range(1,T+1) : N,M = map(int,input().split()) # 정점 개수, 간선 정보 ans = 0 adjL = [[] * m for m in range(N+1)] # 정점별 연결 되어있는 것 체크 리스트 for m in range(M): # s,e 변수들끼리 서로 연결 s,e = map(int,input().split()) adjL[s].append(e) adjL[e].append(s) def df..

[Python][SWEA] 2817. 부분 수열의 합 D3

SW Expert AcademySW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!swexpertacademy.com 🗒️파이썬 코드 풀이T = int(input())for tc in range(1,T+1) : N,K = map(int,input().split()) lst = list(map(int,input().split())) ans,sum,n = 0,0,0 def dfs(n,sum) : global ans if sum == K : # 총 합이 K 일때 ans += 1 return if n >= N: # n이 배열 크기만큼 도달 할 경우 return ..

[Python][SWEA] 959. 두 개의 숫자열 D2

SW Expert AcademySW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!swexpertacademy.com 🗒️파이썬 코드 풀이T = int(input())for tc in range(1,T+1): N,M = map(int,input().split()) # M,N 각각 입력 N_lst = list(map(int,input().split())) # N 리스트 입력 M_lst = list(map(int,input().split())) # M 리스트 입력 result = [] diff_len = abs(N-M) # M과 N 배열의 길이 차이 if N >= M: # N과 M 중 작은 배열의 크기를 큰 배열 크기만큼 0로 채워주기 ..