Algorithm, Data structure/Solved Algorithmic Problem 120

BAEKJOON 2684 - Penney Game

문제: https://www.acmicpc.net/problem/2684 문제Penney’s game is a simple game typically played by two players. One version of the game calls for each player to choose a unique three-coin sequence such as HEADS TAILS HEADS (HTH). A fair coin is tossed sequentially some number of times until one of the two sequences appears. The player who chose the first sequence to appear wins the game.For this prob..

BAEKJOON 2679 - Route Redundancy

문제: https://www.acmicpc.net/problem/2679 문제A city is made up exclusively of one-way streets. Each street in the city has a capacity, the maximum number of cars it can carry per hour. Any route (path) also has a capacity, which is the minimum of the capacities of the streets along that route.The redundancy ratio from point A to point B is the ratio of the maximum number of cars that can get from ..

BACKJOON 2681 - Rancher's Gift

문제: https://www.acmicpc.net/problem/2681 문제Rancher Joel has a tract of land in the shape of a convex quadrilateral that he wants to divide among his sons Al, Bob, Chas and Dave, who wish to continue ranching on their portions, and his daughter Emily, who wishes to grow vegetables on her portion.The center of the tract is most suitable for vegetable farming so Joel decides to divide the land by d..

BAEKJOON 2675 - Repeating Characters

출처: https://www.acmicpc.net/problem/2675 문제For this problem, you will write a program that takes a string of characters, S, and creates a new string of characters, T, with each character repeated R times. That is, R copies of the first character of S, followed by R copies of the second character of S, and so on. Valid characters for S are the QR Code "alphanumeric" characters:0123456789ABCDEFGHI..

BAEKJOON 1052 - 물병

문제: https://www.acmicpc.net/problem/1052 완전 탐색으로 시도를 할 경우 시간 제한안에 풀 수 없기 때문에 다른 방법을 찾아봐야 됩니다.n, k 가 19, 1 일 경우19를 2진수로 표현할 경우 10011 이 됩니다. 이 중 16의 경우 하나의 물병으로 옮겨 담을 수 있고 2와 1이 남게 됩니다. 여기서 1을 더하게 되면 4가 남게 되고 4에 4와 8을 더하게 되면 정답이 됩니다.만약 k가 2일 경우 1만 더하게 되면 16과 4가 남기 때문에 정답이 됩니다.이와 같이 n을 2진수로 표현한 후 bit count 가 k 보다 같거나 작아질 때 까지 물을 더하면 답을 구할 수 있습니다. 1234567891011121314151617181920212223242526272829303..

BAEKJOON 1051 - 숫자 정사각형

문제: https://www.acmicpc.net/problem/1051 특별한 기법없이 완전탐색으로 풀 수 있었던 문제네요. 이미 구해놓은 최대값보다 큰 길이만 검사하는 가지치기 방법을 사용하면 시간 복잡도 문제 없이 풀 수 있는 문제인 것 같습니다. 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253#include #include #include #include #include #include using namespace std; int height, width;int map[51][51]; int getMaxLength(){ int ret = 0; for (int h = 0; ..

BAEKJOON 1038 - 감소하는 수

문제: https://www.acmicpc.net/problem/1038 완전탐색으로 문제를 풀 경우 시간 복잡도가 크기 때문에 다른 방법으로 접근을 해야 했습니다.만약 n이 19일 경우0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 21, 30, 31, 32, 40, 41, 42, 43위와 같은 순서대로 43이 정답이 되는데, 10 이후의 숫자들을 자세히 살펴보면앞자리가 4일 경우 올 수 있는 가짓수는 0, 1, 2, 3 사이의 숫자들 중 한 가지를 고르는 순서 없는 조합의 가짓수임을 알 수 있습니다.즉, 이항계수로 구할 수가 있습니다.따라서 다음과 같이 이항계수를 사용하여 시간 복잡도를 줄여 풀어볼 수 있습니다. 12345678910111213141516171819202122232..

BAEKJOON 1037 - 약수

문제: https://www.acmicpc.net/problem/1037 배열에 진짜 약수들을 담은 후 정렬을 하여 제일 작은 수와 제일 큰 수를 곱하면 답을 구할 수 있습니다. 123456789101112131415161718192021222324252627282930#include #include #include #include #include #include using namespace std; typedef long long ll; int main(){ int n; cin >> n; vector numbers; for (int i = 0; i > num; numbers.push_back(num); } sort(numbers.begin(), numbers.end()); ll ret = numbers..

BAEKJOON 1029 - 그림 교환

문제: https://www.acmicpc.net/problem/1029 memoization과 bit mask 를 이용한 dynamic programming 방법과 재귀함수를 이용한 DFS 을 이용해 풀어봤습니다. my solvingc++1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071#include #include #include #include #include #include using namespace std; const int MAX_N = 15;int n;int prices[MAX_N + 1][MAX_N +..