본문 바로가기

728x90

그 땐 Algorithm했지/그 땐 BaekJoon했지

(8)
[BAEKJOON/Python] no.2644 촌수계산 | DFS/BFS 문제 https://www.acmicpc.net/problem/2644 2644번: 촌수계산 사람들은 1, 2, 3, …, n (1 ≤ n ≤ 100)의 연속된 번호로 각각 표시된다. 입력 파일의 첫째 줄에는 전체 사람의 수 n이 주어지고, 둘째 줄에는 촌수를 계산해야 하는 서로 다른 두 사람의 번호가 주어 www.acmicpc.net 1차 풀이 from collections import deque people_count = int(input()) target1, target2 = map(int, input().split()) relationship_count = int(input()) graph = [[] for _ in range(people_count + 1)] check = [0] * (peopl..
[BAEKJOON/Python] no.1940 주몽 | 정렬 문제 https://www.acmicpc.net/problem/1940 1940번: 주몽 첫째 줄에는 재료의 개수 N(1 ≤ N ≤ 15,000)이 주어진다. 그리고 두 번째 줄에는 갑옷을 만드는데 필요한 수 M(1 ≤ M ≤ 10,000,000) 주어진다. 그리고 마지막으로 셋째 줄에는 N개의 재료들이 가진 고 www.acmicpc.net 1차 풀이 material_count = int(input()) need_num = int(input()) material_num = list(map(int, input().split())) material_num.sort() result = 0 small_num_idx = 0 big_num_idx = material_count - 1 while(True): if s..
[BAEKJOON/Python] no.3085 사탕게임 | 구현, 브루트포스 문제 https://www.acmicpc.net/problem/3085 3085번: 사탕 게임 예제 3의 경우 4번 행의 Y와 C를 바꾸면 사탕 네 개를 먹을 수 있다. www.acmicpc.net 1차 풀이 구글링..ㅎ count = int(input()) candy_list = [list(input()) for _ in range(count)] answer = 0 def check(candy_list): answer = 1 for i in range(count): #0 1 2 cnt = 1 for idx in range(1, count): #1 2 if candy_list[i][idx] == candy_list[i][idx - 1]: cnt += 1 else: cnt = 1 if cnt > answe..
[BAEKJOON/Python] no.14713 앵무새 | Queue 문제 https://www.acmicpc.net/problem/14713 14713번: 앵무새 자가용 비행기를 타고 세계 일주를 하던 pps789와 cseteram은 어느 날 엔진 고장으로 인해 이름 모를 섬에 불시착하게 된다. 그들은 이 섬을 탐험하는 도중 아주 신기한 사실을 알게 되었는데, 바로 www.acmicpc.net 1차 풀이 : 구글링ㅎ from collections import deque bird_count = int(input()) bird_sentence_list = list() for i in range(bird_count): bird_sentence_list.append(deque(map(str, input().split()))) sentence = deque(map(str, inp..
[BAEKJOON/Python] no.1931 회의실 배정 | Greedy 문제 https://www.acmicpc.net/problem/1931 1931번: 회의실 배정 (1,4), (5,7), (8,11), (12,14) 를 이용할 수 있다. www.acmicpc.net 1차 풀이 conference_count = int(input()) schedule = [] for conference in range(conference_count): schedule.append(tuple(map(int, input().split()))) schedule.sort(key=lambda tup: tup[0]) result = [[schedule[0]]] for schedule_time in schedule[1:]: put = 0 for idx, result_time in enumerate(r..
[BAEKJOON/Python] no.16401 과자 나눠주기 | 이진 탐색 문제 https://www.acmicpc.net/problem/16401 16401번: 과자 나눠주기 첫째 줄에 조카의 수 M (1 ≤ M ≤ 1,000,000), 과자의 수 N (1 ≤ N ≤ 1,000,000)이 주어진다. 둘째 줄에 과자 N개의 길이 L1, L2, ..., LN이 공백으로 구분되어 주어진다. 과자의 길이는 (1 ≤ L1, L2, ..., LN www.acmicpc.net 1차 풀이 : 구글링ㅎ 👉🏻도대체가 어떻게 풀어야 하는지 모르겠어서 1시간 고민하고 구글링을 해보았다..ㅎㅎ from sys import stdin input = stdin.readline children_count, snack_count = map(int, input().split()) snacks = list(m..
[BAEKJOON/Python] no.10815 숫자 카드 | 정렬 문제 https://www.acmicpc.net/problem/10815 10815번: 숫자 카드 첫째 줄에 상근이가 가지고 있는 숫자 카드의 개수 N(1 ≤ N ≤ 500,000)이 주어진다. 둘째 줄에는 숫자 카드에 적혀있는 정수가 주어진다. 숫자 카드에 적혀있는 수는 -10,000,000보다 크거나 같고, 10, www.acmicpc.net 1차 풀이 my_card_count = int(input()) card_list = list(map(int, input().split())) number_count = int(input()) find_number = list(map(int, input().split())) for number in find_number: if number in card_list:..
[BAEKJOON/Python] no.2606 바이러스 | DFS/BFS 문제 https://www.acmicpc.net/problem/2606 2606번: 바이러스 첫째 줄에는 컴퓨터의 수가 주어진다. 컴퓨터의 수는 100 이하이고 각 컴퓨터에는 1번 부터 차례대로 번호가 매겨진다. 둘째 줄에는 네트워크 상에서 직접 연결되어 있는 컴퓨터 쌍의 수가 주어 www.acmicpc.net 1차 풀이 computer_count = int(input()) network_count = int(input()) graph = [[] for _ in range(computer_count + 1)] for i in range(network_count): from_com, to_com = map(int, input().split()) graph[from_com].append(to_com) gra..

728x90