전체 글 240

[DFS/BFS]99클럽 코테 스터디 30일차 TIL + 백준/Silver/6080. Bad Grass

[Silver II] Bad Grass - 6080문제 링크성능 요약메모리: 196500 KB, 시간: 904 ms분류너비 우선 탐색, 깊이 우선 탐색, 그래프 이론, 그래프 탐색제출 일자2024년 8월 22일 19:41:02문제 설명Bessie was munching on tender shoots of grass and, as cows do, contemplating the state of the universe. She noticed that she only enjoys the grass on the wide expanses of pasture whose elevation is at the base level of the farm. Grass from elevations just 1 meter hig..

DFS / BFS 종합정리

DFS & BFSBFS와 DFS 정리BFS (너비 우선 탐색)탐색 순서만 구할 때목적: 그래프의 모든 노드를 방문하거나, 특정 노드를 찾고자 할 때.특징: 시작 노드에서 가까운 노드부터 차례대로 방문합니다. 큐(Queue)를 사용하여 구현하며, 레벨별로 탐색합니다.구현:from collections import dequedef bfs(graph, start): visited = set() queue = deque([start]) visited.add(start) while queue: vertex = queue.popleft() print(vertex, end=' ') for neighbor in graph[vertex]: i..

[DFS/BFS]99클럽 코테 스터디 29일차 TIL + 백준/Silver/6188. Clear Cold Water

[Silver II] Clear Cold Water - 6188 문제 링크성능 요약 메모리: 55140 KB, 시간: 1464 ms분류 너비 우선 탐색, 깊이 우선 탐색, 그래프 이론, 그래프 탐색, 트리제출 일자 2024년 8월 21일 21:38:45문제 설명The steamy, sweltering summers of Wisconsin's dairy district stimulate the cows to slake their thirst. Farmer John pipes clear cold water into a set of N (3 She has mapped the entire set of branching pipes and noted that they form a tree with its root ..

[Binary Search]99클럽 코테 스터디 28일차 TIL + 0441-arranging-coins

441. Arranging CoinsEasyYou have n coins and you want to build a staircase with these coins. The staircase consists of k rows where the ith row has exactly i coins. The last row of the staircase may be incomplete.Given the integer n, return the number of complete rows of the staircase you will build. Example 1:Input: n = 5Output: 2Explanation: Because the 3rd row is incomplete, we return 2.Examp..

[Binary Search]99클럽 코테 스터디 27일차 TIL + 0268-missing-number

268. Missing NumberEasyGiven an array nums containing n distinct numbers in the range [0, n], return the only number in the range that is missing from the array. Example 1:Input: nums = [3,0,1]Output: 2Explanation: n = 3 since there are 3 numbers, so all numbers are in the range [0,3]. 2 is the missing number in the range since it does not appear in nums.Example 2:Input: nums = [0,1]Output: 2Exp..

[stack/queue]99클럽 코테 스터디 26일차 TIL + 프로그래머스/2/42587. 프로세스

문제 설명운영체제의 역할 중 하나는 컴퓨터 시스템의 자원을 효율적으로 관리하는 것입니다. 이 문제에서는 운영체제가 다음 규칙에 따라 프로세스를 관리할 경우 특정 프로세스가 몇 번째로 실행되는지 알아내면 됩니다.1. 실행 대기 큐(Queue)에서 대기중인 프로세스 하나를 꺼냅니다.2. 큐에 대기중인 프로세스 중 우선순위가 더 높은 프로세스가 있다면 방금 꺼낸 프로세스를 다시 큐에 넣습니다.3. 만약 그런 프로세스가 없다면 방금 꺼낸 프로세스를 실행합니다. 3.1 한 번 실행한 프로세스는 다시 큐에 넣지 않고 그대로 종료됩니다.예를 들어 프로세스 4개 [A, B, C, D]가 순서대로 실행 대기 큐에 들어있고, 우선순위가 [2, 1, 3, 2]라면 [C, D, A, B] 순으로 실행하게 됩니다.현재 실행 ..

[practice]99클럽 코테 스터디 25일차 TIL + 프로그래머스/1/172928. 공원 산책

문제 설명지나다니는 길을 'O', 장애물을 'X'로 나타낸 직사각형 격자 모양의 공원에서 로봇 강아지가 산책을 하려합니다. 산책은 로봇 강아지에 미리 입력된 명령에 따라 진행하며, 명령은 다음과 같은 형식으로 주어집니다.["방향 거리", "방향 거리" … ]예를 들어 "E 5"는 로봇 강아지가 현재 위치에서 동쪽으로 5칸 이동했다는 의미입니다. 로봇 강아지는 명령을 수행하기 전에 다음 두 가지를 먼저 확인합니다.주어진 방향으로 이동할 때 공원을 벗어나는지 확인합니다.주어진 방향으로 이동 중 장애물을 만나는지 확인합니다.위 두 가지중 어느 하나라도 해당된다면, 로봇 강아지는 해당 명령을 무시하고 다음 명령을 수행합니다.공원의 가로 길이가 W, 세로 길이가 H라고 할 때, 공원의 좌측 상단의 좌표는 (0, ..

[practice]99클럽 코테 스터디 24일차 TIL + 프로그래머스/1/161990. 바탕화면 정리

문제 설명코딩테스트를 준비하는 머쓱이는 프로그래머스에서 문제를 풀고 나중에 다시 코드를 보면서 공부하려고 작성한 코드를 컴퓨터 바탕화면에 아무 위치에나 저장해 둡니다. 저장한 코드가 많아지면서 머쓱이는 본인의 컴퓨터 바탕화면이 너무 지저분하다고 생각했습니다. 프로그래머스에서 작성했던 코드는 그 문제에 가서 다시 볼 수 있기 때문에 저장해 둔 파일들을 전부 삭제하기로 했습니다.컴퓨터 바탕화면은 각 칸이 정사각형인 격자판입니다. 이때 컴퓨터 바탕화면의 상태를 나타낸 문자열 배열 wallpaper가 주어집니다. 파일들은 바탕화면의 격자칸에 위치하고 바탕화면의 격자점들은 바탕화면의 가장 왼쪽 위를 (0, 0)으로 시작해 (세로 좌표, 가로 좌표)로 표현합니다. 빈칸은 ".", 파일이 있는 칸은 "#"의 값을 가..

[Graph]99클럽 코테 스터디 23일차 TIL + 2121-find-if-path-exists-in-graph

2121. Find if Path Exists in GraphEasyThere is a bi-directional graph with n vertices, where each vertex is labeled from 0 to n - 1 (inclusive). The edges in the graph are represented as a 2D integer array edges, where each edges[i] = [ui, vi] denotes a bi-directional edge between vertex ui and vertex vi. Every vertex pair is connected by at most one edge, and no vertex has an edge to itself.You..

[Graph]99클럽 코테 스터디 22일차 TIL + 1916-find-center-of-star-graph

1916. Find Center of Star GraphEasyThere is an undirected star graph consisting of n nodes labeled from 1 to n. A star graph is a graph where there is one center node and exactly n - 1 edges that connect the center node with every other node.You are given a 2D integer array edges where each edges[i] = [ui, vi] indicates that there is an edge between the nodes ui and vi. Return the center of the ..