본문 바로가기

전체 글82

백준_2667_단지번호 붙이기_dfs_bfs_파이썬 문제 링크 2667번: 단지번호붙이기 과 같이 정사각형 모양의 지도가 있다. 1은 집이 있는 곳을, 0은 집이 없는 곳을 나타낸다. 철수는 이 지도를 가지고 연결된 집의 모임인 단지를 정의하고, 단지에 번호를 붙이려 한다. 여 www.acmicpc.net 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 size = int(input()) map1 = [] visited_map = [[False for _ in range(size)] for _ in range(size)] for.. 2023. 8. 4.
백준_1260_DFS와 BFS_0803 해쉬로 하던 습관을 고치고 남들이 하는거 처럼 하니까 코드가 훨씬 깔끔해보이고 기분이 좋다! 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 node_num, line_num, start_num = map(int,input().split()) map1 = [[False for _ in range(node_num+1)] for _ in range(node_num+1)] for i in range(line_num): a,b = map(int,input().split()) map1[a][b] = True map1[b][a] = True def bfs(i): if visited_.. 2023. 8. 3.
백준_2606_바이러스_파이썬_BFS_DFS 후 bfs dfs 모가지를 꺾어서 먹는게 오늘의 목표다! 기존 해쉬쓰는게 너무 비효율적인거 같아 이제 다른 사람처럼 리스트를 만들어서 하는 방향으로 이제 해보겠다! 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 coms_num = int(input()) net_num = int(input()) connect_db = {} already_dict = {} def connect(a,b): if connect_db.get(a) == None: connect_db[a] = [b] else: c.. 2023. 8. 3.
현대_Softeer_level3_택배 마스터 광우_파이썬 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 from itertools import permutations line_num, max_basket, work_time = map(int,input().split()) weight_list = list(map(int,input().split())) def count_total(weight_list): now_index = 0 now_weight = 0 total_weight = 0 now_time = 0 while work_time != now_time: if now_index == line_num: now_index -= line_num now_weight += w.. 2023. 8. 2.