목록생활 (730)
No Rules Rules
트리의 지름 https://www.acmicpc.net/problem/1967 1967번: 트리의 지름 파일의 첫 번째 줄은 노드의 개수 n(1 ≤ n ≤ 10,000)이다. 둘째 줄부터 n-1개의 줄에 각 간선에 대한 정보가 들어온다. 간선에 대한 정보는 세 개의 정수로 이루어져 있다. 첫 번째 정수는 간선이 연 www.acmicpc.net // woohyeon.kim // kim519620.tistory.com #include #include #include #include #include #include using namespace std; map tree; bool visit[10001]; int dp[10001]; void bfs(register int n) { visit[n] = true; q..
두 큐 합 같게 만들기 https://school.programmers.co.kr/learn/courses/30/lessons/118667 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr // woohyeon.kim // kim519620.tistory.com #include #include using namespace std; int solution(vector queue1, vector queue2) { int answer = 0, queue_size = queue1.size(), queue1_idx = 0, queue2_idx = 0; long lon..
성격 유형 검사하기 https://school.programmers.co.kr/learn/courses/30/lessons/118666 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr // woohyeon.kim // kim519620.tistory.com #include #include #include #include using namespace std; string solution(vector survey, vector choices) { map tmp; for(auto i = 0; i < survey.size(); ++i){ auto& survey_i..
트리의 지름 https://www.acmicpc.net/problem/1167 1167번: 트리의 지름 트리가 입력으로 주어진다. 먼저 첫 번째 줄에서는 트리의 정점의 개수 V가 주어지고 (2 ≤ V ≤ 100,000)둘째 줄부터 V개의 줄에 걸쳐 간선의 정보가 다음과 같이 주어진다. 정점 번호는 1부터 V까지 www.acmicpc.net // woohyeon.kim // kim519620.tistory.com #include #include #include #include #include #include using namespace std; map tree; bool visit[100001]; int dp[100001]; void bfs(register int n) { queue q; q.push(n)..

트리의 부모 찾기 https://www.acmicpc.net/problem/11725 11725번: 트리의 부모 찾기 루트 없는 트리가 주어진다. 이때, 트리의 루트를 1이라고 정했을 때, 각 노드의 부모를 구하는 프로그램을 작성하시오. www.acmicpc.net // woohyeon.kim // kim519620.tistory.com #include #include #include #include #include using namespace std; map tree; int ans[100001]; bool visit[100001]; void bfs() { queue q; q.push(1); visit[1] = true; while (!q.empty()) { auto v = q.front(); q.po..
DSLR https://www.acmicpc.net/problem/9019 9019번: DSLR 네 개의 명령어 D, S, L, R 을 이용하는 간단한 계산기가 있다. 이 계산기에는 레지스터가 하나 있는데, 이 레지스터에는 0 이상 10,000 미만의 십진수를 저장할 수 있다. 각 명령어는 이 레지스터에 www.acmicpc.net // woohyeon.kim #include #include using namespace std; inline int calc_D(register int n) { return (n > T; for (register int t = 0, A, B, D, S, L, R; t < T; ++t) { bool visit[10000]{ false }; string dp[10000]{ ""..
숨바꼭질 4 https://www.acmicpc.net/problem/13913 13913번: 숨바꼭질 4 수빈이는 동생과 숨바꼭질을 하고 있다. 수빈이는 현재 점 N(0 ≤ N ≤ 100,000)에 있고, 동생은 점 K(0 ≤ K ≤ 100,000)에 있다. 수빈이는 걷거나 순간이동을 할 수 있다. 만약, 수빈이의 위치가 X일 www.acmicpc.net // woohyeon.kim // kim519620.tistory.com #include #include #include #include #include using namespace std; pair dp[100001]; bool visit[100001]; int main() { ios::sync_with_stdio(false), cin.tie(NUL..
플로이드 2 https://www.acmicpc.net/problem/11780 11780번: 플로이드 2 첫째 줄에 도시의 개수 n이 주어지고 둘째 줄에는 버스의 개수 m이 주어진다. 그리고 셋째 줄부터 m+2줄까지 다음과 같은 버스의 정보가 주어진다. 먼저 처음에는 그 버스의 출발 도시의 번호가 www.acmicpc.net // woohyeon.kim // kim519620.tistory.com #include #include #include using namespace std; int N, M; int ans1[101][101]; int ans2[101][101]; deque q; void solve(register int f, register int t) { if (ans2[f][t] == 0) ..
LCS 2 https://www.acmicpc.net/problem/9252 9252번: LCS 2 LCS(Longest Common Subsequence, 최장 공통 부분 수열)문제는 두 수열이 주어졌을 때, 모두의 부분 수열이 되는 수열 중 가장 긴 것을 찾는 문제이다. 예를 들어, ACAYKP와 CAPCAK의 LCS는 ACAK가 된다. www.acmicpc.net // woohyeon.kim // kim519620.tistory.com #include #include #include #include using namespace std; int dp[1001][1001]{ 0 }; stack ans; int main() { ios::sync_with_stdio(false), cin.tie(NULL);..

가장 긴 증가하는 부분 수열 5 https://www.acmicpc.net/problem/14003 14003번: 가장 긴 증가하는 부분 수열 5 첫째 줄에 수열 A의 크기 N (1 ≤ N ≤ 1,000,000)이 주어진다. 둘째 줄에는 수열 A를 이루고 있는 Ai가 주어진다. (-1,000,000,000 ≤ Ai ≤ 1,000,000,000) www.acmicpc.net // woohyeon.kim // kim519620.tistory.com #include #include #include using namespace std; int N; long long arr[1000000], tmp[1000000]; stack ans1; stack ans2; int binary_search(register int..