본문 바로가기
  • 안녕하세요,,, 안녕히가세요,,,,

프로그램/코딩테스트28

삼성 Expert 14178 1차원 정원 import math count = 0 for _ in range(int(input())): N, D = map(int, input().split()) count += 1 num = 1 + D * 2 print(f'#{count} {math.ceil(N/num)}')​ 2022. 6. 13.
삼성 Expert 1206 View for i in range(1, 11): ans = 0 case = input() ar = list(map(int, input().split())) for j in range(2, len(ar) - 2): if ar[j] > ar[j - 2] and ar[j] > ar[j - 1] and ar[j] > ar[j + 1] and ar[j] > ar[j + 2]: ans += ar[j] - max(ar[j - 1], ar[j - 2], ar[j + 1], ar[j + 2]) j += 2 print(f"#{i} {ans}") 2022. 6. 13.
삼성 Expert 1244 최대 상금 ans = 0 def dfs(count): global ans temp = int(''.join(ar)) if count == 0: ans = max(ans, temp) return for i in range(len(ar)): for j in range(i + 1, len(ar)): ar[i], ar[j] = ar[j], ar[i] temp_key = ''.join(ar) if chk.get((temp_key, count - 1), 1): chk[(temp_key, count - 1)] = 0 dfs(count - 1) ar[i], ar[j] = ar[j], ar[i] for test_case in range(1, int(input()) + 1): ans = 0 ar, n = input().split().. 2022. 6. 13.
삼성 Expert 1208 Flatten https://swexpertacademy.com/main/code/problem/problemDetail.do SW Expert Academy SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요! swexpertacademy.com for test_case in range(1, 11): ans = 0 dump = int(input()) ar = list(map(int, input().split())) for i in range(dump): max_num = max(ar) min_num = min(ar) if max_num == min_num: break ar[ar.index(max_num)] -= 1 ar[ar.index(min_num)] += 1 ans = max(ar) - mi.. 2022. 6. 13.
백준 7562 나이트의 이동 from collections import deque dy = (1, 1, -1, -1, 2, 2, -2, -2) dx = (2, -2, 2, -2, 1, -1, 1, -1) N = 0 def err(ex, ey): return 0 2022. 6. 13.
백준 1743 음식물 피하기 import sys sys.setrecursionlimit(10 ** 8) dy = (0, 1, 0, -1) dx = (1, 0, -1, 0) N, M, K = map(int, input().split()) trash_map = [[False for _ in range(M)] for _ in range(N)] check_map = [[False for _ in range(M)] for _ in range(N)] answer = 0 size = 0 for _ in range(K): r, c = map(int, input().split()) trash_map[r - 1][c - 1] = True def err(ey, ex): return 0 2022. 6. 13.
백준 1987 알파벳 from collections import deque dy = (0, 1, 0, -1) dx = (1, 0, -1, 0) R, C = map(int, input().split()) move_board = [input() for _ in range(R)] check = [[set() for _ in range(C)] for _ in range(R)] ans = 0 deq = deque() deq.append((0, 0, move_board[0][0])) check[0][0].add(move_board[0][0]) def err(a, b): return 0 2022. 6. 13.
백준 2178 미로 탐색 from collections import deque dy = (0, 1, 0, -1) dx = (1, 0, -1, 0) # n -> y m -> x n, m = map(int, input().split()) labyrinth = [input() for _ in range(n)] # n개의 배열 m의 길이 check = [[False] * m for _ in range(n)] deq = deque() deq.append((0, 0, 1)) check[0][0] = True def err(a, b): return 0 2022. 6. 13.
백준 11724 연결 요소의 개수 import sys sys.setrecursionlimit(10 ** 8) input = sys.stdin.readline n, m = map(int, input().split()) connect = [[False] * n for _ in range(n)] for _ in range(m) : x, y = map(int, input().split()) connect[x-1][y-1] = True connect[y-1][x-1] = True answer = 0 check = [False] * n def dfs(i): for j in range(n): if not check[j] and connect[i][j] : check[j] = True dfs(j) for i in range(n): if not chec.. 2022. 6. 13.
백준 1449 수리공 항승 import sys input = sys.stdin.readline n, l = map(int, input().split()) packing_list = [False] * 1001 answer = 0 times = 0 for i in map(int, input().split()): packing_list[i] = True #1000 회 반복 while times 2022. 6. 13.
백준 1931 회의실 배정 import sys input = sys.stdin.readline answer = 0 time = 0 time_table = [] #입력부 for _ in range(int(input())) : start, end = map(int, input().split()) time_table.append((end, start)) #연산부 time_table.sort() for end, start in time_table : if time 2022. 6. 13.
백준 3085 사탕 게임 import sys input = sys.stdin.readline answer = 1 num = int(input()) num_list = [list(input()) for _ in range(num)] def find_max_count() : global answer for i in range(num) : count = 1 for j in range(1,num) : if num_list[i][j] == num_list[i][j-1] : count += 1 answer = max(answer, count) else : count = 1 for j in range(num) : count = 1 for i in range(1,num) : if num_list[i][j] == num_list[i-1][j] .. 2022. 6. 13.
백준 10448 유레카 이론 from itertools import combinations import sys input = sys.stdin.readline tri = [n * (n + 1) // 2 for n in range(46)] for _ in range(int(input())) : yes = 0 num = int(input()) for i in range(1, 46) : for j in range(i, 46) : for k in range(j, 46) : if tri[i]+tri[j]+tri[k] == num : yes = 1 print(yes) 완전 탐색을 이용해 해결했다. 테스트케이스가 1000까지 이기 때문에 넉넉하게 46번째까지 미리 구해서 배열에 넣어주었다. 겹치지 않는 3개의 유레카 수의 합이 입력받는 값과 같.. 2022. 6. 13.
백준 3040 백설 공주와 일곱 난쟁이 from itertools import combinations nanjeng = [] for _ in range(9) : nanjeng.append(int(input())) for i in combinations(nanjeng,7) : nanjeng_sum = sum(i) if nanjeng_sum == 100 : for k in i : print(k) break 완전 탐색을 이용해 해결했다. combinations 함수를 통해 7가지 인자를 가지는 부분 집합을 모두 구해 합이 100되는 경우를 출력했다. 2022. 6. 13.
백준 2075 N번째 큰 수 import heapq, sys input = sys.stdin.readline heap = [] num = int(input()) for _ in range(num) : array = list(map(int,input().split())) if heap : for a in array : if a > heap[0] : heapq.heappop(heap) heapq.heappush(heap, a) else : for a in array : heapq.heappush(heap, a) print(heap[0]) 힙을 이용해 해결했다. 모든 수를 다 넣고 해결하기에는 시간 복잡도가 매우 커진다. 파이썬은 최소 힙을 이용하기 때문에 힙의 크기를 N으로 제한하고, 0번째에 있는 수를 출력하게 되면 N번째 큰 수가 .. 2022. 6. 13.
백준 1935 후위 표기식2 import sys input = sys.stdin.readline count = int(input()) formula = input().strip() num = [] result = [] for _ in range(count) : num.append(int(input())) for thhh in formula : if 'A' 2022. 6. 13.