[프로그래머스] 사칙연산(C++)
·
개발/알고리즘
문제 링크https://school.programmers.co.kr/learn/courses/30/lessons/1843 프로그래머스SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 코드 구현#include #include #include #include int max_val = std::numeric_limits::max();int min_val = std::numeric_limits::min();using namespace std;int solution(vector arr){ int n = (arr.size() + 1) / 2; // 숫자 개수 vector nums; vector ops; for (..
[백준] 2252번: 줄 세우기(C++)
·
개발/알고리즘
문제 링크https://www.acmicpc.net/problem/2252 코드 구현#include #include #include using namespace std;int main(){ int N, M; cin >> N >> M; vector> graph(N + 1); vector degree(N + 1, 0); queue q; for (int i = 0; i > A >> B; graph[A].push_back(B); degree[B]++; } // 차수가 0인 학생먼저 큐에 삽입 for (int i = 1; i 해결 방법인접리스트와 차수를 저장하는 벡터를 이용하여 A -> B를 가리키는 인접리스트에 B의 차수를 증가시켜 저장차수가 낮은 학생부터 큐에 삽입하고 출력하면서 그 학생보다 뒤에 와..
[백준] 1806번: 부분합(C++)
·
개발/알고리즘
문제 링크https://www.acmicpc.net/problem/1806 코드 구현#include #include #include using namespace std;int main(){ int N, S; cin >> N >> S; vector sequence(N); for (int i = 0; i > sequence[i]; } int answer = N + 1; int sum = 0, start = 0; for (int end = 0; end = S) { answer = min(answer, end - start + 1); sum -= sequence[start]; start++; } } if (answer == N + 1) cout 해결 방법Start 와 End 지점을 0으로 ..
[프로그래머스] 단속카메라(C++)
·
개발/알고리즘
문제 링크https://school.programmers.co.kr/learn/courses/30/lessons/42884 프로그래머스SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 코드 구현#include #include #include #include using namespace std;bool Compare(const vector& a, const vector& b){ return a[1] > routes) { int answer = 1; // 진출 시점 기준으로 오름차순 정렬 sort(routes.begin(), routes.end(), Compare); int out = rout..
[Unity] 유니티 생명주기 콜백 함수
·
개발/Unity
유니티 생명 주기Unity에서 MonoBehaviour 스크립트는 다양한 생명주기(Lifecycle) 콜백 함수를 제공한다.이 함수들은 특정 타이밍에 자동으로 호출되며, 주로 객체의 초기화, 게임 루프에서의 반복 실행, 충돌 처리, 파괴 등과 관련되어 있다.아래는 MonoBehaviour 생명주기 콜백 함수의 실행 순서와 각 함수의 간단한 설명이다. 자세한 이미지와 설명은 Unity Documentation을 참고하자.https://docs.unity3d.com/kr/2021.3/Manual/ExecutionOrder.html 이벤트 함수의 실행 순서 - Unity 매뉴얼Unity 스크립트를 실행하면 사전에 지정한 순서대로 여러 개의 이벤트 함수가 실행됩니다. 이 페이지에서는 이러한 이벤트 함수를 소개하..
[백준] 2206번: 벽 부수고 이동하기(C++)
·
개발/알고리즘
문제 링크https://www.acmicpc.net/problem/2206 코드 구현#include #include #include using namespace std;struct Node{ int y, x; int dist; bool broken; // 벽을 부쉈는지};int N, M;vector> map;vector> directions = { {-1, 0}, {1, 0}, {0, -1}, {0, 1} };bool CanMove(int y, int x){ return (y >= 0 && y = 0 && x >> visited(N, vector>(M, vector(2, false))); queue q; q.push({0, 0, 1, false}); visited[0][0][0] = true; whil..
[프로그래머스] 이중우선순위큐(C++)
·
개발/알고리즘
문제 링크https://school.programmers.co.kr/learn/courses/30/lessons/42628 프로그래머스SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 코드 구현#include #include #include #include using namespace std;vector solution(vector operations){ // 이중우선순위큐 multiset 이용 std::multiset dq; for (const auto& op : operations) { // 삽입 if (op[0] == 'I') { int ..
[백준] 9663번: N-Queen(C++)
·
개발/알고리즘
문제 링크https://www.acmicpc.net/problem/9663 코드 구현#include #include #include using namespace std;int N;// 현재 행에 다른 퀸이 있는지bool isSameRow(int placedRow, int currentRow){ return placedRow == currentRow;}// 대각선에 다른 퀸이 있는지bool isDiagonal(int placedCol, int placedRow, int currentCol, int currentRow){ // 대각선에 있으면 가로 길이 차이 = 세로 길이 차이 return abs(placedCol - currentCol) == abs(placedRow - currentRow);}// 퀸을..
[프로그래머스] 정수 삼각형(C++)
·
개발/알고리즘
문제 링크https://school.programmers.co.kr/learn/courses/30/lessons/43105 프로그래머스SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 코드 구현#include #include #include using namespace std;int solution(vector> triangle){ int n = triangle.size(); vector> dp(n, vector(n, 0)); // dp 테이블 맨 아랫쪽 초기화 for (int i = 0; i = 0; --i) { for (int j = 0; j 해결 방법거쳐간 숫자의 최댓값을 구..
[백준] 16236번: 아기 상어(C++)
·
개발/C++
문제 링크https://www.acmicpc.net/problem/16236 코드 구현#include #include #include #include #include using namespace std;int n;vector> space;vector> dirs = { {-1, 0}, {1, 0}, {0, -1}, {0, 1} };bool canMove(int y, int x, int sharkSize){ // 박스 범위 내에 있고 물고기의 크기가 상어 크기와 같거나 작은지 if (y >= 0 && y = 0 && x & a, const tuple& b) { // 거리 우선 if (get(a) != get(b)) return get(a) > get(b); // y 우선 if (get(a) != g..
[프로그래머스] 단어 변환(C++)
·
개발/알고리즘
문제 링크https://school.programmers.co.kr/learn/courses/30/lessons/43163 프로그래머스SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 코드 구현#include #include #include #include using namespace std;bool IsNeighbor(const string& a, const string& b){ // 두 단어를 비교하여 하나만 단어가 다른 경우를 찾음 int diff = 0; for (int i = 0; i 1) return false; } return true;}int solution(string begin..
[백준] 7576번: 토마토(C++)
·
개발/알고리즘
문제 링크https://www.acmicpc.net/problem/7576 코드 구현#include #include #include #include using namespace std;vector> box;int days[1000][1000];queue> q;vector> dir = { {0, -1}, {0, 1}, {-1, 0}, {1, 0} };bool IsValid(int x, int y){ if (x >= 0 && x = 0 && y now = q.front(); q.pop(); for (int i = 0; i > m >> n; box.resize(n); for (int i = 0; i > t; box[i].push_back(t); // 처음부터 익어있는 토마토 큐에 삽입 if ..
[백준] 1967번: 트리의 지름(C++)
·
개발/알고리즘
문제 링크https://www.acmicpc.net/problem/1967 코드 구현#include #include #include using namespace std;vector>> tree;vector visited;int maxDist = 0, farNode = 0;void dfs(int node, int dist){ visited[node] = true; if (dist >= maxDist) { maxDist = dist; farNode = node; } for (const pair pair : tree[node]) { int neighbor = pair.first; int weight = pair.second; if (!visited[neighbor]) { dfs(neighbor..
[프로그래머스] 가장 먼 노드(C++)
·
개발/알고리즘
문제 링크https://school.programmers.co.kr/learn/courses/30/lessons/49189 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 코드 구현#include #include #include #include using namespace std;vector> graph;vector visited;queue q;void bfs(int start){ visited[start] = 1; q.push(1); while (!q.empty()) { int now = q.front(); q.pop(); for (int n..
[프로그래머스] 길 찾기 게임(C++)
·
개발/알고리즘
문제 링크https://school.programmers.co.kr/learn/courses/30/lessons/42892 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 코드 구현#include #include #include using namespace std;// 노드 정의struct Node{ int id, x, y; Node* left = nullptr; Node* right = nullptr; Node(int _id, int _x, int _y) : id(_id) , x(_x) , y(_y) {}};// 이진 트리 정의class..