알고리즘 108

[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로 채워주기 ..

[Python][SWEA] 3752. 가능한 시험 점수 D4

SW Expert AcademySW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!swexpertacademy.com🗒️파이썬 코드 풀이T = int(input())for tc in range(1,T+1): N = int(input()) lst = list(map(int,input().split())) # 입력값 result = [0] # 결과값 저장 visit = [1] + [0] * sum(lst) # 방문 체크 for i in range(len(lst)) : for j in range(len(result)): if visit[lst[i]+result[j]] == 0 : # 방문은 안했을 경우 ..