전체 글 142

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 +..

BAEKJOON 1032 - 명령 프롬프트

문제: https://www.acmicpc.net/problem/1032 오랜만에 손에 잡은 문제이자, 문제가 너무 쉬워 어딘가에 함정이 있을거라 한참을 찾아본 문제네요 ㅋㅋ; 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950#include #include #include #include #include #include using namespace std;const int MAX_N = 50; int main(){ string characters[MAX_N][MAX_N]; int n; int strLength = 0; cin >> n; for (int i = 0; i > str; strLen..

BAEKJOON 1030 - 프렉탈 평면

문제: https://www.acmicpc.net/problem/1030 값을 미리 배열에 모두 넣어두면 편할테지만 메모리 문제로 규칙을 찾아 값을 얻는 방법을 사용했습니다. my solvingc++123456789101112131415161718192021222324252627282930313233343536373839404142434445464748#include #include #include #include #include using namespace std; int s, n, k;int length; int getColor(int y, int x){ if (y == 1) int temp = 0; int unit = length / n; int border = (n - k) / 2; while (..

BAEKJOON 1028 - 다이아몬드 광산

문제: https://www.acmicpc.net/problem/1028 memoization 과 현재 최대값보다 작은 다이아몬드는 계산하지 않는 가지치기 방법으로 시간 복잡도를 줄여 풀었습니다. my solvingc++12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712..