본문 바로가기

컴퓨터51

1092 배, 2212 센서, 1461 도서관 1092 배, 2212 센서, 1461 도서관 1092 배 # 첫번째 풀이(시간 초과, 노는 크레인 생김) n = int(input()) # 크레인 개수 crane = list(map(int, input().split())) crane = sorted(crane, reverse=True) m = int(input()) # 박스 개수 box = list(map(int, input().split())) box = sorted(box) len_of_box = len(box) count = 0 if crane[0] box[len_of_box - 1]: len_of_box -= 1 count.. 2020. 10. 12.
5585 거스름돈, 1439 뒤집기, 2012 등수 매기기 5585 거스름돈, 1439 뒤집기, 2012 등수 매기기 5585 거스름돈 # 첫번째 풀이 money_list = [500, 100, 50, 10, 5, 1] money = int(input()) money = 1000 - money count = 0 for i in money_list: if money < i: continue else: count += money // i money = money % i print(count) # 두번째 풀이(더 간단하게) money = 1000 - int(input()) count = 0 for i in [500, 100, 50, 10, 5, 1]: count += money // i money %= i print(count) 1439 뒤집기 s = input() .. 2020. 10. 12.
1012 유기농 배추, 1325 효율적인 해킹, 10282 해킹 1012 유기농 배추, 1325 효율적인 해킹, 10282 해킹 1012 유기농 배추 import sys sys.setrecursionlimit(100000) def dfs(v, w): visited[v][w] = True directions = [(-1, 0), (1, 0), (0, -1), (0, 1)] for dx, dy in directions: nx, ny = v + dx, w + dy if nx = n or ny = m: continue if adj[nx][ny] and not visited[nx][ny]: dfs(nx, ny) for _ in range(int(input())): m, n, k = map(int, input().split()) visit.. 2020. 10. 8.
1260 DFS와 BFS, 1697 숨바꼭질, 2606 바이러스 1260 DFS와 BFS, 1697 숨바꼭질, 2606 바이러스 1260 DFS와 BFS from collections import deque def dfs(v): print(v, end=' ') visited[v] = True for e in adj[v]: if visited[e] == False: dfs(e) def bfs(v): q = deque([v]) while q: v = q.popleft() if visited[v] == False: visited[v] = True print(v, end=' ') for e in adj[v]: if visited[e] == False: q.append(e) n, m, v = map(int, input().split()) adj = [[] for _ in ra.. 2020. 10. 7.