본문 바로가기

Algorithm 💡272

[Softeer 기출문제] 전광판 import sys t = int(input()) def set_time(n): time = [0]*7 if n == 0: time[0],time[1],time[2],time[4],time[5],time[6] = 1,1,1,1,1,1 elif n == 1: time[2],time[5] = 1,1 elif n == 2: time[0],time[2],time[3],time[4],time[6] = 1,1,1,1,1 elif n == 3: time[0],time[2],time[3],time[5],time[6] = 1,1,1,1,1 elif n == 4: time[1],time[2],time[3],time[5] = 1,1,1,1 elif n == 5: time[0],time[1],time[3],time[5],ti.. 2023. 5. 30.
[백준 16236번] 아기 상어 from collections import deque n = int(input()) area = [] result = 0 shark_size = 2 ate_fish = 0 nx = [-1,1,0,0] ny = [0,0,-1,1] for i in range(n): area.append(list(map(int,input().split()))) for i in range(n): for j in range(n): if area[i][j] == 9: shark_location_x, shark_location_y = i, j def bfs(x,y,sharkSize): visited = [[False]*n for _ in range(n)] distence = [[0]*n for _ in range(n)] visite.. 2023. 5. 27.
[HackerRank] Knapsack def unboundedKnapsack(k, arr): # Write your code here row = len(arr) col = k dp = [[0]*(k+1) for _ in range(row+1)] for i in range(1,row+1): dp[i][0] = 1 for i in range(1,row+1): for j in range(1,col+1): if j >= arr[i-1]: dp[i][j] = dp[i-1][j] + dp[i][j-arr[i-1]] else: dp[i][j] = dp[i-1][j] for i in range(col,-1,-1): if dp[row][i] != 0: return i 이번 문제는 주어진 배열(arr)의 원소들을 가지고 만들 수 있는 타겟 값(k)을 초과하지.. 2023. 5. 20.
[HackerRank] Count Luck def countLuck(matrix, k): row = len(matrix) col = len(matrix[0]) nx = [-1,1,0,0] ny = [0,0,-1,1] start_x, start_y = 0, 0 count = 0 graph = [] for i in range(row): graph.append(list(matrix[i])) for i in range(row): for j in range(col): if graph[i][j] == 'M': start_x, start_y = i, j # Write your code here def dfs(area, x, y): # visited[x][y] = True if area[x][y] == '*': return True direct_count = .. 2023. 5. 19.
[HackerRank] Caesar Cipher def caesarCipher(s, k): # Write your code here length = len(s) str_list = list(s) k %= 26 for i in range(length): char_ord = ord(str_list[i]) if char_ord >= ord('A') and char_ord ord('Z'): diff = ord('Z') - char_ord index = (ord('A')-1) + (k-diff) str_list[i] = chr(index) else: str_list[i] = chr(char_ord+k) elif char_ord >= ord('a') and char_ord ord('z'): diff = ord('z') - char_ord index = (ord(.. 2023. 5. 19.
[HackerRank] Two Characters def alternate(s): # Write your code here result_list = [] def gen_comb(arr,n): result = [] if n == 0: return [[]] for i in range(len(arr)): element = arr[i] rest_arr = arr[i+1:] for c in gen_comb(rest_arr,n-1): result.append([element]+c) return result def validate(arr): length = len(arr) if length >=2: first, second = arr[0],arr[1] for j in range(length): if j%2 == 0 and arr[j] != first: return .. 2023. 5. 19.