Pokeball - Pokemon

til 32

99클럽 코테 스터디 12일차 TIL + BFS(C++)

문제[백준] 7576번: 토마토https://www.acmicpc.net/problem/7576 코드#include #include #include using namespace std;int M, N; // M: 가로(열), N: 세로(행)int visited[1001][1001]; // 토마토가 익은 날짜를 저장하는 배열int tomato[1001][1001]; // 토마토가 저장된 상자의 상태를 저장하는 배열queue> q; // BFS를 위해 (x, y) 좌표를 저장하는 큐int ans; // 모든 토마토가 익기까지 걸리는 최대 날짜int dx[4] = {-1, 1, 0, 0};int dy[4] = {0, 0, -1..

99클럽 TIL 2024.11.09

99클럽 코테 스터디 10일차 TIL + BFS(C++)

문제[백준] 18352번: 특정 거리의 도시 찾기https://www.acmicpc.net/problem/18352 코드#include #include #include #include using namespace std;vector dist(300001, -1); // -1로 초기화하여 방문하지 않음을 나타냄vector graph[300001];int N, M, K, X, A, B;bool found = false;void bfs(int start) { dist[start] = 0; queue q; q.push(start); while (!q.empty()) { int x = q.front(); q.pop(); for (int y : graph..

99클럽 TIL 2024.11.06

99클럽 코테 스터디 9일차 TIL + BFS(C++)

문제[백준] 7562번: 나이트의 이동https://www.acmicpc.net/problem/7562 코드#include #include #include using namespace std;int T;int l;int now_x, now_y;int target_x, target_y;int dx[8] = {-2, -2, -1, -1, 1, 1, 2, 2};int dy[8] = {1, -1, 2, -2, 2, -2, 1, -1};void bfs(int start_x, int start_y) { vector> visited(l, vector(l, 0)); // 방문 배열(이동 횟수 저장) 초기화 queue> q; // 큐 초기화 q.push({start_x, start_y}); // 시..

99클럽 TIL 2024.11.05

99클럽 코테 스터디 7일차 TIL + 완전탐색(C++)

코드#include #include using namespace std;vector vowels = {'A', 'E', 'I', 'O', 'U'};int cnt = 0; // 현재까지 몇 번째 단어인지 저장하는 변수int ans = 0; // 목표 단어의 순서를 저장하는 변수string target; // 찾고자 하는 단어void dfs(string current) { // 현재 단어가 목표 단어와 같다면 결과 변수에 순서를 저장하고 종료 if (current == target) { ans = cnt; return; } // 단어의 길이가 5이면 더 이상 탐색하지 않음 if (current.size() == 5) return; // 다음 알파벳을..

99클럽 TIL 2024.11.03

99클럽 코테 스터디 4일차 TIL + DFS(C++)

문제[백준] 24479번: 알고리즘 수업 - 깊이 우선 탐색 1https://www.acmicpc.net/problem/24479 코드#include #include #include using namespace std;int idx = 1; // 방문 순서vector visited(100001);vector graph[100001];void dfs(int x) { visited[x] = idx++; // 정점 x의 방문 순서를 저장하고 idx를 1 증가시킴 for (int y : graph[x]) { if (!visited[y]) dfs(y); }}int main(void) { int N, M, R; cin >> N >> M >> R; //..

99클럽 TIL 2024.10.31

99클럽 코테 스터디 3일차 TIL + 이진탐색(C++)

문제[프로그래머스] 입국심사https://school.programmers.co.kr/learn/courses/30/lessons/43238 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 코드#include #include using namespace std;long long solution(int n, vector times) { sort(times.begin(), times.end()); long long answer = 0; long long left = 1; long long right = n * (long long)times.back(); while (left = n..

99클럽 TIL 2024.10.30