diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 57287e0..0000000 --- a/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -.DS_Store -.dSYM \ No newline at end of file diff --git a/Algorithm/WhatisAlgorithm.md b/Algorithm/WhatisAlgorithm.md deleted file mode 100644 index 5db4b66..0000000 --- a/Algorithm/WhatisAlgorithm.md +++ /dev/null @@ -1,18 +0,0 @@ -# 알고리즘이란? -
- -알고리즘이란 어떤 작업을 수행하기 위해 입력을 받아 원하는 출력을 만들어내는 과정을 기술한 것이다. -알고리즘을 설계하기 위해서는 우선 해야 할 작업을 명확하게 면시해야 한다. -출력과 입력에 의해 "무엇을"하는지에 대해 명시할 수 있다. - -## 알고리즘은 명확하고 효율적이어야 한다. -* 명확성 : 모호하지 않고 이해하기 쉬워야한다. 자세한 것과는 다르다. -* 효율성 : 입력의 크기가 충분히 클 때 알고리즘의 효율성에 따라 수행 시간이 크게 차이날 수 있다. - -## 알고리즘을 명확하고 효율적으로 설계하고, 이를 잘 분석하여야한다. -자원, 메모리, 시간을 효율적으로 관리하기 위해서는 좋은 알고리즘이 필요하다. - -## 알고리즘으로 어떤 문제를 해결하는가? -- 네비게이션 구현, ATM 기기, 신용카드, 인터넷 검색 - - diff --git a/BeakjoonOnlineJudge/1021/1021.cpp b/BeakjoonOnlineJudge/1021/1021.cpp deleted file mode 100644 index 182b302..0000000 --- a/BeakjoonOnlineJudge/1021/1021.cpp +++ /dev/null @@ -1,105 +0,0 @@ -/* -https://www.acmicpc.net/problem/1021 -BOJ 1021번 회전하는 큐 - -(1) 접근 -입력받은 순서대로 큐에서 pop하는 문제이다. -큐의 특성 상 front만을 pop할 수 있기 때문에 순서대로 pop하기 위해서는 -큐를 회전시켜야한다. -왼쪽으로 한 칸 회전시키면 가장 앞에 있는 것이 맨 뒤로 이동되고, -오른쪽으로 한 칸 회전시키면 가장 뒤에 있는 것이 맨 앞으로 이동된다. -그래서 왼쪽, 오른쪽으로 회전시킨 횟 수를 구하여 출력하는 문제이다. - -(2) 해결 -회전 시키기 위해서는 맨 뒤의 값을 pop하여 맨 앞에 위치시킬 수 있어야하고, 반대로 맨 앞의 값을 pop하여 맨 뒤로 위치시킬 수 있어야한다. -이는 deque을 사용하면 간단해진다. - -다음으로 회전할 방향을 결정해야한다. -회전을 결정하기 위해서 뽑아야할 값의 위치를 앞에서 부터 n번째, 뒤로 부터 k번째로 계산한다. n과 k 둘중에 작은 것을 회전방향으로 결정한다. - -회전할 때마다 count에 1을 더하여 계산하고 마지막으로 출력한다. -*/ - -#include -#include -#include -#include - -using namespace std; - -int N; -int M; -int ans; - -deque sequence; -deque dq; - -void calNum2(int count) -{ - for (int i = 0; i < count; i++) - { - dq.push_back(dq.front()); - dq.pop_front(); - } - ans += count; -} - -void calNum3(int count) -{ - for (int i = 0; i < count; i++) - { - dq.push_front(dq.back()); - dq.pop_back(); - } - ans += count; -} - -void compareSequence() -{ - int calCount; - for (int i = 0, j = dq.size() - 1; i < dq.size(), j >= 0; i++, j--) - { - if (dq[i] == sequence.front()) - { - calNum2(i); - break; - } - else if (dq[j] == sequence.front()) - { - calNum3(dq.size() - j); - break; - } - } -} - -int main() -{ - int temp; - - cin >> N >> M; - for (int i = 0; i < M; i++) - { - cin >> temp; - sequence.push_back(temp); - } - - for (int i = 1; i <= N; i++) - { - dq.push_back(i); - } - - while (sequence.size() > 0) - { - if (dq.front() == sequence.front()) - { - dq.pop_front(); - sequence.pop_front(); - } - else - { - compareSequence(); - } - } - - cout << ans; -} diff --git a/BeakjoonOnlineJudge/1037/1037.cpp b/BeakjoonOnlineJudge/1037/1037.cpp deleted file mode 100644 index 7efaedd..0000000 --- a/BeakjoonOnlineJudge/1037/1037.cpp +++ /dev/null @@ -1,43 +0,0 @@ -/* -https://www.acmicpc.net/problem/1037 -BOJ 1037번 약수 - -(1) 접근 -1과 자기자신을 제외한 약수가 주어졌을 때 가장 큰 값과 가장 큰 수를 곱하면 N을 구할 수 있다. - -(2) 해결 -vector의 라이브러리 함수를 사용하여 간단하게 해결했다. -sort 함수를 사용하여 정렬 후 vector.front() * vector.back()을 계산하여 -답을 도출한다. - -algorithm 헤더파일을 추가하여 sort 함수를 사용한다. -vector.begin() : 벡터의 맨 처음 주소값 -vector.end() : 벡터의 마지막 주소값 -vector.front() : 벡터의 맨 처음 값 -vector.back() : 벡터의 마지막 값 -vector.erase(지우고 싶은 주소) : 해당 주소의 값을 삭제 - */ -#include -#include -#include -#include - -using namespace std; - -int N; -vector realDivisor; - -int main() -{ - cin >> N; - for(int i = 0; i < N; i++) - { - int temp; - cin >> temp; - realDivisor.push_back(temp); - } - sort(realDivisor.begin(), realDivisor.end()); - - cout << realDivisor.front() * realDivisor.back() << endl; - return 0; -} \ No newline at end of file diff --git a/BeakjoonOnlineJudge/10773/10773.cpp b/BeakjoonOnlineJudge/10773/10773.cpp deleted file mode 100644 index 15ccac1..0000000 --- a/BeakjoonOnlineJudge/10773/10773.cpp +++ /dev/null @@ -1,40 +0,0 @@ -/* -https://www.acmicpc.net/problem/10773 -BOJ 10773번 제로 - -(1) 접근 -스택을 이용하여 쉽게 해결할 수 있다. - -(2) 해결 -c++의 vector형식을 사용하여 스택을 구현했다. -0이 입력되었을 때 스택에서 pop하고 0 이외의 수가 입력되었을 때 그 수를 push한다. -모든 수를 입력받은 후에 스택의 모든 수를 더하면 정답이 도출된다. - */ -#include -#include -#include -#include - -using namespace std; - -int K; -vector stack; -int sum; - -int main() -{ - int temp; - cin >> K; - for (int i = 0; i < K; i++) - { - cin >> temp; - if (temp == 0) - stack.pop_back(); - else stack.push_back(temp); - } - - for (int i = 0; i < stack.size(); i++) - sum += stack[i]; - - cout << sum; -} diff --git a/BeakjoonOnlineJudge/10828/10828.cpp b/BeakjoonOnlineJudge/10828/10828.cpp deleted file mode 100644 index dcd62a9..0000000 --- a/BeakjoonOnlineJudge/10828/10828.cpp +++ /dev/null @@ -1,93 +0,0 @@ -/* -https://www.acmicpc.net/problem/10828 - -BOJ 10828번 스택 - -(1) 접근 -벡터를 이용하여 쉽게 풀 수 있는 문제이다. -stack 자료형을 사용할 수도 있다. - -(2) 해결 -vector 라이브러리를 활용하여 문제를 해결햇다. -v.push_back(value) : value를 vector의 마지막 인덱스로 삽입합니다. -v.pop() : vector의 마지막 값을 삭제합니다. -v.size() : vector에 저장된 값의 개수를 반환합니다. -v.empty() : vector가 비어있다면 true, 아니면 -false를 반환합니다. -v. back() : vector의 마지막 값을 반환합니다. -*/ - -#include -#include -#include -#include -#include - -using namespace std; - -int N; -string command; -int value; -vector stack; - -static map m; - -void settingCommand() -{ - m["push"] = 0; - m["pop"] = 1; - m["size"] = 2; - m["empty"] = 3; - m["top"] = 4; -} - -void excuteCommand(string comm) -{ - switch (m[comm]) - { - case 0: - cin >> value; - stack.push_back(value); - break; - case 1: - if(stack.empty()) - cout << -1 << endl; - else - { - value = stack.back(); - cout << value << endl; - stack.pop_back(); - } - break; - case 2: - cout << stack.size() << endl; - break; - case 3: - if(stack.empty()) - cout << 1 << endl; - else cout << 0 << endl; - break; - case 4: - if(stack.empty()) - cout << -1 << endl; - else cout << stack.back() << endl; - break; - default: - return; - } -} - -int main() -{ - ios_base::sync_with_stdio(false); - - cin.tie(NULL); - - settingCommand(); - cin >> N; - for(int i = 0; i < N; i++) - { - cin >> command; - excuteCommand(command); - } -} \ No newline at end of file diff --git a/BeakjoonOnlineJudge/10830/10830.cpp b/BeakjoonOnlineJudge/10830/10830.cpp deleted file mode 100644 index ed18ca6..0000000 --- a/BeakjoonOnlineJudge/10830/10830.cpp +++ /dev/null @@ -1,100 +0,0 @@ -/* -https://www.acmicpc.net/problem/10830 -BOJ 10830번 행렬 제곱 - -(1) 접근 -입력받은 행렬을 제곱하는 문제이다. -제곱의 특성을 이용하여 분할정복하는 문제이다. - -(2) 해결 -2의 8제곱은 4의 4제곱이고, 4의 4제곱은 16의 제곱이다. -이 특성을 이용하여 분할정복하면 N제곱을 O(log(N))만에 수행할 수 있다. -재귀함수를 이용하여 N이 홀수인지 짝수인지를 판단하여 그에 맞는 처리를 해주면 된다. -홀수라면 행렬의 N - 1제곱에 행렬을 한번 더 곱하고, -짝수라면 행렬의 제곱을 N/2제곱한다. - -(3) 마무리 -행렬 곱셈과 제곱수를 분할정복하는 알고리즘을 알고 있으면 잘 풀 수 있는 문제입니다. -1000으로 나눈 나머지를 출력해야하기 때문에 행렬 값에 1000이 들어오는 경우를 체크하지 않아서 한번에 통과하지 못했네요. -앞으로는 엣지케이스를 더 잘 체크해야겠습니다. -*/ -#include -#include - -using namespace std; -typedef vector< vector > matrix; -long long int N; -long long int B; - -matrix createMatrix(int size) -{ - matrix T; - for(int i = 0; i < size; i++) - { - vector column; - for(int j = 0; j < size; j++) - { - column.push_back(0); - } - T.push_back(column); - } - return T; -} - -matrix multiplyMatrix(matrix A, matrix B) -{ - matrix T = createMatrix(N); - for(int i = 0; i < N; i++) - { - for(int j = 0; j < N; j++) - { - for(int k = 0; k < N; k++) - { - T[i][j] = (T[i][j] + (A[i][k] * B[k][j])) % 1000; - } - } - } - return T; -} - -matrix power(matrix T, long long int squaredCount) -{ - if(squaredCount == 1) - return T; - else if(squaredCount % 2 == 0) - return power(multiplyMatrix(T, T), squaredCount / 2); - else - return multiplyMatrix(T, power(T, squaredCount - 1)); -} - -int main() -{ - ios_base::sync_with_stdio(false); - cin.tie(NULL); - cout.tie(NULL); - - matrix M; - - cin >> N >> B; - M = createMatrix(N); - - for(int i = 0; i < N; i++) - { - for(int j = 0; j < N; j++) - { - cin >> M[i][j]; - M[i][j] %= 1000; - } - } - - M = power(M, B); - - for(int i = 0; i < N; i++) - { - for(int j = 0; j < N; j++) - { - printf("%lld ", M[i][j]); - } - printf("\n"); - } -} \ No newline at end of file diff --git a/BeakjoonOnlineJudge/10866/10866.cpp b/BeakjoonOnlineJudge/10866/10866.cpp deleted file mode 100644 index 9e52431..0000000 --- a/BeakjoonOnlineJudge/10866/10866.cpp +++ /dev/null @@ -1,104 +0,0 @@ -/* -https://www.acmicpc.net/problem/10866 -BOJ 10866번 덱 - -(1) 접근 -덱 관련 명령어를 입력받으면 명령어에 맞게 출력하는 문제이다. -덱은 스택과 큐의 장점을 합친 자료구조이고, 사용자가 원하는 순서로 입력과 출력을 할 수 있다. - -(2) 해결 -C++의 stl 컨테이너를 활용하여 구현하였다. -명령어를 입력받으면 이를 int형으로 맵핑하여 switch문을 동작시켜 해당 명령어에 맞는 동작을 수행하도록 한다. -*/ -#include -#include -#include -#include - -using namespace std; - -int N; -deque d; -map command; - -void settingCommand() -{ - command["push_front"] = 1; - command["push_back"] = 2; - command["pop_front"] = 3; - command["pop_back"] = 4; - command["size"] = 5; - command["empty"] = 6; - command["front"] = 7; - command["back"] = 8; -} - -void excuteCommand(string c) -{ - int X; - - switch (command[c]) - { - case 1: - cin >> X; - d.push_front(X); - break; - case 2: - cin >> X; - d.push_back(X); - break; - case 3: - if(d.size() > 0) - { - cout << d.front() << "\n"; - d.pop_front(); - } - else cout << -1 << "\n"; - break; - case 4: - if(d.size() > 0) - { - cout << d.back() << "\n";; - d.pop_back(); - } - else cout << -1 << "\n"; - break; - case 5: - cout << d.size() << "\n"; - break; - case 6: - if(d.empty()) - cout << 1 << "\n"; - else cout << 0 << "\n"; - break; - case 7: - if(d.size() > 0) - cout << d.front() << "\n"; - else cout << -1 << "\n"; - break; - case 8: - if(d.size() > 0) - cout << d.back() << "\n"; - else cout << -1 << "\n"; - break; - default: - break; - } -} - -int main() -{ - cin.tie(0); - cin.sync_with_stdio(false); - - string c; - settingCommand(); - - cin >> N; - for(int i = 0; i < N; i++) - { - cin >> c; - excuteCommand(c); - } - -} diff --git a/BeakjoonOnlineJudge/11051/11051.cpp b/BeakjoonOnlineJudge/11051/11051.cpp deleted file mode 100644 index c48aaa5..0000000 --- a/BeakjoonOnlineJudge/11051/11051.cpp +++ /dev/null @@ -1,46 +0,0 @@ -/* -https://www.acmicpc.net/problem/11051 -이항계수 11050번, 11051번 이항계수 1, 2 - -(1) 접근 -이항계수는 N개의 수 중에서 K를 뽑는 경우의 수를 뜻한다. -11050번과 11051번은 입력 범위와 10007의 나머지를 출력하는 것만 다르고, -11051번의 소스코드로 11050번도 통과할 수 있기때문에 한꺼번에 작성하였다. -11050번은 입력범위가 작기 때문에 팩토리얼 자체를 동적 프로그램(DP)으로 구한 후 N! / K!(N - K)!의 공식을 DP에서 값을 가져와 해결했다. 하지만 11051번은 -값의 범위가 크고 나머지끼리의 나눗셈으로 원래의 값의 나머지를 구하기가 어려웠다. 이항계수 자체를 DP 배열에 저장하여 해결해야했다. - -(2) 해결 -파스칼의 삼각형을 이용하여 이항계수 DP를 만들 수 있었다. -DP의 점화식을 표현하면 -if (j == 0) - factorialDP[i][j] = 1; -else - factorialDP[i][j] = (factorialDP[i - 1][j] + factorialDP[i - 1][j - 1]) -이고 이를 11051번에서는 10007의 나머지로 출력한다. -*/ -#include -#include - -#define MOD 10007 - -using namespace std; - -int N, K; -int answer; -int factorialDP[1001][1001] = {0,}; - -int main() -{ - cin >> N >> K; - for (int i = 0; i <= N; i++) - { - for (int j = 0; j <= i; j++) - { - if (j == 0) - factorialDP[i][j] = 1; - else - factorialDP[i][j] = (factorialDP[i - 1][j] + factorialDP[i - 1][j - 1]) % MOD; - } - } - cout << factorialDP[N][K]; -} \ No newline at end of file diff --git a/BeakjoonOnlineJudge/11401/11401 b/BeakjoonOnlineJudge/11401/11401 deleted file mode 100755 index d74bd65..0000000 Binary files a/BeakjoonOnlineJudge/11401/11401 and /dev/null differ diff --git a/BeakjoonOnlineJudge/11401/11401.cpp b/BeakjoonOnlineJudge/11401/11401.cpp deleted file mode 100644 index 09edad0..0000000 --- a/BeakjoonOnlineJudge/11401/11401.cpp +++ /dev/null @@ -1,62 +0,0 @@ -/* -https://www.acmicpc.net/problem/11401 -BOJ 11401번 이항계수3 - -(1) 접근 -N개 중에서 K개를 뽑는 경우의 수인 '이항계수'를 구하는 문제이다. -하지만 N의 범위가 4000000까지이기 때문에 -이항계수 nCk = n!/k!(n-k)!의 공식을 이용하여야 제한 시간 1초안에 문제를 해결할 수 있다. -하지만 P = 1000000007으로 나눈 나머지를 출력해야하기 때문에 -n!%P/k!(n-k)!%P로 계산하게되면 분모가 0이 될 수 있어서 이를 바로 계산할 수 없다. - -그래서 페르마의 소정리를 사용해야한다. -페르마의 소정리는 소수 P와 서로소인 수의 P-1승을 P로 나눈 나머지는 무조건 1이라는 정리이다. -이를 사용하면 1/k!(n-k)!%P를 k!(n-k)!의 제곱수 % P로 표현할 수 있다. - -(1/k!(n-k)!)의 P-1승을 P로 나눈다면 1이 될 것이다. -이를 -(1/k!(n-k)!)(1/k!(n-k)!)의 P-2승 % P = 1 -으로 표현할 수 있다. 이를 다시 정리하면 -(1/k!(n-k)!) % P = (1/k!(n-k)!)의 P-2승 % P이다. - -이항계수 공식을 이 식을 활용하여 표현한다면 -n!%P * k!(n-k)의 P-2승 %P이 된다. - -(2) 해결 -제한 시간 1초안에 문제를 해결하기 위해서는 O(N^2)이 되서는 안된다. -이를 위해서 팩토리얼은 DP를 사용하여 O(N)의 시간복잡도로 전처리한다. -N과 K가 입력되면 K!(N-K)!를 미리 계산해놓은 팩토리얼 값을 이용하여 계산하고 -P-2승을 계산해야한다. 이는 분할정복을 사용하면 O(log(P))의 시간복잡도로 계산할 수 있다. 마지막으로 N!를 미리 계산해놓은 팩토리얼 값에서 읽어와 곱셈하면 정답이 출력된다. -*/ -#include - -using namespace std; - -int N, K; -long long int fac[4000001]; -long long int P = 1000000007; - -long long int power(long long int num, long long int powerOf) -{ - if(powerOf == 1) - return num % P; - else if(powerOf % 2 == 0) - return power((num * num) % P, powerOf / 2) % P; - else return (num * power(num, powerOf - 1)) % P; -} - -int main() -{ - fac[0] = 1; - fac[1] = 1; - for(int i = 2; i < 4000001; i++) - { - fac[i] = (fac[i - 1] * i) % P; - } - - scanf("%d %d", &N, &K); - long long int KfacNminusKfac = (fac[K] * fac[N - K]) % P; - long long int KfacNminusKfacPower = power(KfacNminusKfac, P - 2); - long long int ans = (fac[N] * KfacNminusKfacPower) % P; - printf("%lld", ans); -} \ No newline at end of file diff --git a/BeakjoonOnlineJudge/11401/11401.dSYM/Contents/Info.plist b/BeakjoonOnlineJudge/11401/11401.dSYM/Contents/Info.plist deleted file mode 100644 index 0901cc8..0000000 --- a/BeakjoonOnlineJudge/11401/11401.dSYM/Contents/Info.plist +++ /dev/null @@ -1,20 +0,0 @@ - - - - - CFBundleDevelopmentRegion - English - CFBundleIdentifier - com.apple.xcode.dsym.11401 - CFBundleInfoDictionaryVersion - 6.0 - CFBundlePackageType - dSYM - CFBundleSignature - ???? - CFBundleShortVersionString - 1.0 - CFBundleVersion - 1 - - diff --git a/BeakjoonOnlineJudge/11401/11401.dSYM/Contents/Resources/DWARF/11401 b/BeakjoonOnlineJudge/11401/11401.dSYM/Contents/Resources/DWARF/11401 deleted file mode 100644 index 8428b2a..0000000 Binary files a/BeakjoonOnlineJudge/11401/11401.dSYM/Contents/Resources/DWARF/11401 and /dev/null differ diff --git a/BeakjoonOnlineJudge/11444/11444.cpp b/BeakjoonOnlineJudge/11444/11444.cpp deleted file mode 100644 index f42da3c..0000000 --- a/BeakjoonOnlineJudge/11444/11444.cpp +++ /dev/null @@ -1,85 +0,0 @@ -/* -https://www.acmicpc.net/problem/11444 -BOJ 11444번 피보나치 수 6 - -(1) 접근 -피보나치 수를 행렬을 이용해서 구할 수 있다. -어떻게 풀어야할지 감이 오지 않아서 다른 블로그들을 참고하였다. -Fn+1 Fn = 1 1 -Fn Fn-1 1.0 의 n제곱 -이라는 행렬식이 등장하게 되는데 이는 행렬의 곱과 분할정복을 이용한 제곱 구하기를 통하여 문제를 해결할 수 있었다. - -(2) 해결 -10830번에서 행렬의 제곱에 대한 문제를 풀었었다. -그래서 이를 다시 한번 구현했고, 제곱할 행렬의 값을 위에서 설명한 행렬으로 설정했다. -N을 입력받은 후, N 제곱한 후 Fn인 (1,0)의 값을 출력하면 된다. -*/ -#include -#include - -using namespace std; - -typedef vector< vector< long long int> > matrix; -long long int N; - -matrix createMatrix(int size) -{ - matrix T; - for(int i = 0; i < size; i++) - { - vector column; - for(int j = 0; j < size; j++) - { - column.push_back(0); - } - T.push_back(column); - } - return T; -} - -matrix multipleMatrix(matrix A, matrix B) -{ - matrix T = createMatrix(2); - for(int i = 0; i < A.size(); i++) - { - for(int j = 0; j < A.size(); j++) - { - for(int k = 0; k < A.size(); k++) - { - T[i][j] = (T[i][j] + (A[i][k] * B[k][j])) % 1000000007; - } - } - } - return T; -} - -matrix sqrtMatrix(matrix P, long long int N) -{ - if(N == 1) - return P; - else if(N % 2 == 0) - return sqrtMatrix(multipleMatrix(P, P), N / 2); - else - return multipleMatrix(P, sqrtMatrix(P, N -1)); -} - -int main() -{ - matrix P = createMatrix(2); - P[0][0] = 1; - P[0][1] = 1; - P[1][0] = 1; - P[1][1] = 0; - scanf("%lld", &N); - - if(N < 1) - { - printf("%d\n", 0); - return 0; - } - - P = sqrtMatrix(P, N); - printf("%lld\n", P[01][0] % 1000000007); - - return 0; -} diff --git a/BeakjoonOnlineJudge/11724/11724.cpp b/BeakjoonOnlineJudge/11724/11724.cpp deleted file mode 100644 index 96c6c87..0000000 --- a/BeakjoonOnlineJudge/11724/11724.cpp +++ /dev/null @@ -1,91 +0,0 @@ -/* - https://www.acmicpc.net/problem/11724 - BOJ 11724번 연결 요소의 개수 - (1) 접근 - 연결 요소란 그래프에서 연결된 노드끼리 묶었을 때 묶음의 개수이다. - 예제 입력1을 예로 들면 - 1, 2, 5 / 3, 4, 6 두가지 묶음으로 표현된다. 즉, 연결 요소는 2개이다. - - (2) 해결 - BFS, DFS 를 이용하여 연결된 노드를 체크하고, - 다시 방문되지 않은 노드부터 이를 반복한다. - 반복 횟수를 출력하면 정답이다. - */ -#pragma warning(disable: 4996) -#include -#include -#include -#include -#include -#include - -using namespace std; - -int N, M; -int cnt = 0; -vector Node[1001]; -bool checkedNode[1001]; - -void BFS(int start) -{ - vector queue; - - checkedNode[start] = true; - for(int i = 0; i < Node[start].size(); i++) - { - queue.push_back(Node[start][i]); - checkedNode[Node[start][i]] = true; - } - - while (queue.size() > 0) - { - int firstIn = queue[0]; - for(int i = 0; i < Node[firstIn].size(); i++) - { - if(checkedNode[Node[firstIn][i]] == false) - { - queue.push_back(Node[firstIn][i]); - checkedNode[Node[firstIn][i]] = true; - } - } - queue.erase(queue.begin()); - } -} - -int checkRemainNode() -{ - for(int i = 1; i <= N; i++) - { - if(!checkedNode[i]) - return i; - } - return -1; -} - -int main() -{ - int start, arrive; - int startNode; - - cin >> N >> M; - for(int i = 0; i < M; i++) - { - cin >> start >> arrive; - Node[start].push_back(arrive); - Node[arrive].push_back(start); - } - - while(true) - { - startNode = checkRemainNode(); - if(startNode < 0) - break; - - BFS(startNode); - cnt++; - } - - cout << cnt << endl; - - return 0; -} \ No newline at end of file diff --git a/BeakjoonOnlineJudge/11866/11866.cpp b/BeakjoonOnlineJudge/11866/11866.cpp deleted file mode 100644 index 20967e5..0000000 --- a/BeakjoonOnlineJudge/11866/11866.cpp +++ /dev/null @@ -1,63 +0,0 @@ -/* -https://www.acmicpc.net/problem/11866 -BOJ 11866번 요세푸스 문제 0 - -(1) 접근 -1 ~ N개의 수를 오름차순으로 정렬하고 원형으로 나열한 뒤 K번째의 수를 반복하여 추출했을 때 추출되는 순서에 따라서 생성되는 수열을 요세푸스 수열이라고 한다. 이 때 N과 K가 주어지고, 요세푸스 수열을 구하여 출력하는 문제이다. -큐 자료구조를 이용하여 해결하였다. - -(2) 해결 -큐의 특성을 이용하여 K번째 이전 순서의 수들을 pop하여 다시 큐에 푸시하면 -K번째 수를 뽑을 때 반복적으로 맨 앞에서 부터 순서를 계산하여 이 수열을 구할 수 있다. - -ex) 5 3 -1 2 3 4 5 -> 3번째 '3' 추출 -> 1 2 4 5 -1 2 4 5 -> '4'에서 부터 3번째 수 추출 -> 마지막 순서인 '5'에서 '1'로 넘어가며 순서를 계산해야함 -> '1' 추출 - -큐를 사용한다면 '1', '2'가 맨뒤로 이동되고 '3'이 추출되면 -4 5 1 2 -> 맨 처음부터 세번째인 '1' 추출 - -큐를 이용함으로써 구현이 용이해진다. -*/ -#pragma warning (disable : 4996) -#include -#include -#include -#include - -using namespace std; - -int N; -int K; - -queue q; -vector ans; - -int main() -{ - cin >> N >> K; - for (int i = 1; i <= N; i++) - { - q.push(i); - } - - - while (q.size() > 0) - { - for (int i = 0; i < K - 1; i++) - { - q.push(q.front()); - q.pop(); - } - ans.push_back(q.front()); - q.pop(); - } - - cout << "<"; - for (int i = 0; i < N; i++) - { - if (i == N - 1) - cout << ans[i] << ">" << endl; - else cout << ans[i] << ", "; - } -} \ No newline at end of file diff --git a/BeakjoonOnlineJudge/13305/13305.cpp b/BeakjoonOnlineJudge/13305/13305.cpp deleted file mode 100644 index 8366f00..0000000 --- a/BeakjoonOnlineJudge/13305/13305.cpp +++ /dev/null @@ -1,50 +0,0 @@ -/* -https://www.acmicpc.net/problem/13305 -BOJ 13305번 : 주유소 - -(1) 접근 -이 문제는 왼쪽 도시부터 오른쪽 도시까지 이동하는 최소 비용을 구하는 문제이다. 석유 가격이 더 낮은 도시를 만나기 전까지의 거리만큼 주유하고 다시 주유를 할 도시를 만나면 이를 반복한다. - -(2) 해결 -모든 입력을 받은 후 처음의 오일 가격을 저장한 후 -다음 도시로 이동한다고 가정한다. 만약 다음 도시의 오일 가격이 더 저렴하다면 더 저렴한 기름을 주유하는 것으로 하고 더 비싸다면 기존의 저장된 가격의 오일을 주유하는 것으로 한다. 이 과정을 마지막 도시까지 반복한다. -*/ -#include -#include -#include -#include - -using namespace std; - -long long int totalPrice; -int N; -vector oilprice; -vector dist; -int nowPrice = 1000000000; - -int main() -{ - int temp; - - cin >> N; - for (int i = 0; i < N - 1; i++) - { - cin >> temp; - dist.push_back(temp); - } - - for (int i = 0; i < N; i++) - { - cin >> temp; - oilprice.push_back(temp); - } - - for (int i = 0; i < N - 1; i++) - { - if (oilprice[i] < nowPrice) - nowPrice = oilprice[i]; - totalPrice += (dist[i] * nowPrice); - } - - cout << totalPrice; -} \ No newline at end of file diff --git a/BeakjoonOnlineJudge/1676/1676.cpp b/BeakjoonOnlineJudge/1676/1676.cpp deleted file mode 100644 index 258bc30..0000000 --- a/BeakjoonOnlineJudge/1676/1676.cpp +++ /dev/null @@ -1,34 +0,0 @@ -/* -https://www.acmicpc.net/problem/1676 -BOJ 1676번 팩토리얼 0의 개수 - -(1) 접근 -N!을 계산한 뒤, 맨 뒤에서부터 0의 개수를 세는 문제이다. -하지만 N의 범위가 1 ~ 500이므로, 500!을 계산하면 int형의 오버플로우가 발생한다. 그래서 다른 방법으로 접근해야한다. -N!에서 5와 2의 개수를 세는 방법으로 문제를 해결했다. 5 x 2가 1개 있을 때마다 0이 하나씩 생성된다. 또한, 팩토리얼의 특성 상 N까지의 수의 절반은 짝수이다. 따라서 2가 5보다 무조건 많기 때문에 5의 개수만 세면 된다. - -(2) 해결 -N에 대해서 5를 나눈 몫과 25를 나눈 몫, 125를 나눈 몫을 모두 더하면 된다.(500보다 작은 5의 배수) -5를 제외한 수를 나눈 몫을 더하는 이유는 25를 예로 들어 설명하자면, -25의 경우 5 x 5이기 때문에 5로 나누면 1개만 카운팅된다. 그래서 25를 한번 더 나누어 세지 않은 5를 체크한다. -*/ -#include -#include - -using namespace std; - -int N; -int ans = 0; - -int main() -{ - cin >> N; - int five = 5; - while (N >= five) - { - ans += N / five; - five *= 5; - } - cout << ans; - return 0; -} \ No newline at end of file diff --git a/BeakjoonOnlineJudge/17298/17298.cpp b/BeakjoonOnlineJudge/17298/17298.cpp deleted file mode 100644 index 2363bed..0000000 --- a/BeakjoonOnlineJudge/17298/17298.cpp +++ /dev/null @@ -1,52 +0,0 @@ -/* -https://www.acmicpc.net/problem/17298 -BOJ 17298번 오큰수 - -(1) 접근 -수열에서 자신의 위치보다 왼쪽의 수 중 제일 먼저 나온 자신보다 큰 수를 찾아 배열을 만드는 문제이다. -스택 자료구조를 이용하여 문제를 해결할 수 있었다. - -(2) 해결 -만약 입력받은 수가 스택의 top 값보다 크다면 입력받은 수를 '오큰수'로 한다. 오큰수를 구한 수는 팝한다. pop된 수의 '오큰수'는 자신의 입력받은 순서로 지정하여 저장한다. 입력받은 수는 다시 스택에 푸시한다. 이를 반복하다보면 '오큰수'가 있는 수들은 스택에서 모두 pop되고, '오큰수'가 없는 수들만 남게 된다. -이 수들의 순서에는 -1을 넣어 저장한다. 마지막으로 순서에 맞게 저장된 값들을 차례대로 출력하면 정답이 된다. -*/ -#include -#include -#include -#include - -using namespace std; - -int N; -int ans[1000000]; -stack < pair > numberStack; - -int main() -{ - int temp; - cin >> N; - for (int i = 0; i < N; i++) - { - cin >> temp; - while (numberStack.size() > 0 && temp > numberStack.top().first) - { - int index = numberStack.top().second; - ans[index] = temp; - numberStack.pop(); - } - pair inputNum(temp, i); - numberStack.push(inputNum); - } - - while (numberStack.size() > 0) - { - int index = numberStack.top().second; - ans[index] = -1; - numberStack.pop(); - } - - for (int i = 0; i < N; i++) - { - cout << ans[i] << " "; - } -} \ No newline at end of file diff --git a/BeakjoonOnlineJudge/1780/1780.cpp b/BeakjoonOnlineJudge/1780/1780.cpp deleted file mode 100644 index 0c13e28..0000000 --- a/BeakjoonOnlineJudge/1780/1780.cpp +++ /dev/null @@ -1,71 +0,0 @@ -/* -https://www.acmicpc.net/problem/1780 -BOJ 1780번 종이의 개수 - -(1) 접근 -이전에 풀었던 쿼드트리 문제에서 나누는 종이의 개수가 4개에서 9개로 늘어난 문제이다. - -(2) 해결 -쿼드트리에서도 현재 체크하고 있는 종이 덩어리에 다른 값이 있는지 없는지를 체크하고, 다른 것이 있다면 4등분하여 다시 이를 반복하여 체크하였다. -이 문제는 9등분을 해야함으로 덩어리가 모두 같은 값인지 체크한 후 다른 값이 있다면 범위를 9등분하여 이를 반복적으로 체크한다. 또한 새로운 종이의 종류가 조건에 추가되어있기 떄문에 모두 같은 값일 때 체크하는 종류를 하나 더 추가하여 구현하면 해결된다. -쿼드트리문제와 99% 유사한 문제라고 생각한다. -*/ -#include -using namespace std; - -int paperArray[2187][2187]; -int totalBlue = 0; -int totalWhite = 0; -int totalBlack = 0; - -void dividePaper(int N, int startIndexY, int startIndexX) -{ - for (int i = startIndexY; i < startIndexY + N; i++) - { - for (int j = startIndexX; j < startIndexX + N; j++) - { - if (paperArray[startIndexY][startIndexX] != paperArray[i][j]) - { - int dividedN = N / 3; - dividePaper(dividedN, startIndexY, startIndexX); - dividePaper(dividedN, startIndexY, startIndexX + dividedN); - dividePaper(dividedN, startIndexY, startIndexX + ( 2 * dividedN)); - dividePaper(dividedN, startIndexY + dividedN, startIndexX); - dividePaper(dividedN, startIndexY + dividedN, startIndexX + dividedN); - dividePaper(dividedN, startIndexY + dividedN, startIndexX + (2 * dividedN)); - dividePaper(dividedN, startIndexY + (2 * dividedN), startIndexX); - dividePaper(dividedN, startIndexY + (2 * dividedN), startIndexX + dividedN); - dividePaper(dividedN, startIndexY + (2 * dividedN), startIndexX + (2 * dividedN)); - return; - } - } - } - if (paperArray[startIndexY][startIndexX] == -1) - totalBlue++; - else if (paperArray[startIndexY][startIndexX] == 0) - totalWhite++; - else totalBlack++; -} - -int main() -{ - ios_base::sync_with_stdio(false); - cin.tie(NULL); cout.tie(NULL); - - int N; - cin >> N; - - for (int i = 0; i < N; i++) - { - for (int j = 0; j < N; j++) - cin >> paperArray[i][j]; - } - - dividePaper(N, 0, 0); - - cout << totalBlue << "\n"; - cout << totalWhite << "\n"; - cout << totalBlack << "\n"; - - return 0; -} \ No newline at end of file diff --git a/BeakjoonOnlineJudge/18258/18258.cpp b/BeakjoonOnlineJudge/18258/18258.cpp deleted file mode 100644 index 044c7dd..0000000 --- a/BeakjoonOnlineJudge/18258/18258.cpp +++ /dev/null @@ -1,96 +0,0 @@ -/* -https://www.acmicpc.net/problem/18258 - -BOJ 18258번 큐2 - -(1) 접근 -큐의 성질을 구현하는 문제이다. queue 자료구조를 사용하여 해결했다. - -(2) 해결 -switch문을 사용하기 위해서 map을 만들었고 이를 통해 입력받은 커맨드를 인트형으로 변환하여 스위치문을 사용하였다. -나머지는 queue자료구조의 라이브러리 함수를 사용하여 해결했다. -다만 cin, cout을 사용하면서 시간초과가 발생했는데, 원인을 몰라서 한참 헤매었다. 개행문자를 endl 대신 \n을 사용하고 main함수에 cin.tie(0); - cin.sync_with_stdio(false); 코드를 추가하니 시간초과 없이 해결할 수 있었다. -*/ - -#include -#include -#include -#include -#include - -using namespace std; - -int N; -string command; -int num; - -map m; - -queue q; - -void settingCommand() -{ - m["push"] = 0; - m["pop"] = 1; - m["size"] = 2; - m["empty"] = 3; - m["front"] = 4; - m["back"] = 5; -} - -void excuteCommand(string command) -{ - switch (m[command]) - { - case 0: - cin >> num; - q.push(num); - break; - case 1: - if (q.empty()) - cout << -1 << '\n'; - else - { - cout << q.front() << '\n'; - q.pop(); - } - break; - case 2: - cout << q.size() << '\n'; - break; - case 3: - if (q.empty()) - cout << 1 << '\n'; - else - cout << 0 << '\n'; - break; - case 4: - if (q.empty()) - cout << -1 << '\n'; - else - cout << q.front() << '\n'; - break; - case 5: - if (q.empty()) - cout << -1 << '\n'; - else - cout << q.back() << '\n'; - break; - default: - break; - } -} -int main() -{ - cin.tie(0); - cin.sync_with_stdio(false); - - settingCommand(); - cin >> N; - for (int i = 0; i < N; i++) - { - cin >> command; - excuteCommand(command); - } -} \ No newline at end of file diff --git a/BeakjoonOnlineJudge/1874/1874.cpp b/BeakjoonOnlineJudge/1874/1874.cpp deleted file mode 100644 index 5428769..0000000 --- a/BeakjoonOnlineJudge/1874/1874.cpp +++ /dev/null @@ -1,61 +0,0 @@ -/*https://www.acmicpc.net/problem/1874 -BOJ 1874번 스택 수열 - -(1) 접근 -수열을 입력 받은 후 1~N 까지를 입력받으며 수열과 일치하게 만들 수 있도록 스택에 push와 pop하는 과정을 출력하는 문제이다. -만약 스택의 top이 입력받은 수열의 현재 인덱스에 저장된 값과 일치한다면 계속해서 pop하고, 그렇지 않다면 push만 하고 넘어가는 식으로 문제를 해결했다. - -(2) 해결 -vector를 선언하여 수열을 입력받았다. -for문을 통해서 1~N까지 stack에 푸시하고, while문을 통해 스택의 top과 수열의 특정 인덱스에 저장된 값을 비교한다. 만약 while문에 들어온다면 스택에서 pop하고 특정 인덱스++를 하여 다음 값을 비교한다. -*/ -#pragma warning(disable: 4996) -#include -#include -#include -#include -#include - -using namespace std; - -int N; -int temp; -int stackCount = 0; -vector seq; -stack numStack; -string ans; - -int main() -{ - cin >> N; - for (int i = 0; i < N; i++) - { - scanf("%d", &temp); - seq.push_back(temp); - } - - for (int i = 1; i <= N; i++) - { - numStack.push(i); - ans += '+'; - - while (numStack.empty() == false && seq[stackCount] == numStack.top()) - { - numStack.pop(); - ans += '-'; - stackCount++; - } - } - - if (numStack.empty() == false) - cout << "NO"; - else - { - for (int i = 0; i < ans.size(); i++) - { - printf("%c\n", ans[i]); - } - } - - return 0; -} \ No newline at end of file diff --git a/BeakjoonOnlineJudge/18870/18870.cpp b/BeakjoonOnlineJudge/18870/18870.cpp deleted file mode 100644 index 4d96f64..0000000 --- a/BeakjoonOnlineJudge/18870/18870.cpp +++ /dev/null @@ -1,54 +0,0 @@ -/* -https://www.acmicpc.net/problem/18870 -BOJ 18870번 좌표압축 - -(1) 접근 -가장 작은 수를 0으로하여 수열의 큰 순서를 압축한다. -100 10 1 을 압축하면 2 1 0이 된다. -벡터와 맵을 활용하여 해결할 수 있었다. - -(2) 해결 -입력받은 수열을 복사하여 정렬하고, 정렬된 순서대로 mapping을 한다. -map에 value가 없는 경우에만 count를 올리고 map[key] = count로 value를 설정한다. -다시 정렬되지 않은 수열을 순서대로 map에 넣어 mapping하면 압축된 값이 차례대로 출력된다. -*/ -#include -#include -#include -#include - -using namespace std; - -int N; -vector number; -vector sorted; -map m; -vector ans; -int main() -{ - cin >> N; - for(int i = 0; i < N; i++) - { - int temp; - cin >> temp; - number.push_back(temp); - } - - sorted = number; - sort(sorted.begin(), sorted.end()); - - int count = 0; - for(int i = 0; i < N; i++) - { - if(m[sorted[i]] == 0) - { - count++; - m[sorted[i]] = count; - } - } - - for(int i = 0; i < N; i++) - { - cout << m[number[i]] - 1 << " "; - } -} \ No newline at end of file diff --git a/BeakjoonOnlineJudge/1920/1920.cpp b/BeakjoonOnlineJudge/1920/1920.cpp deleted file mode 100644 index efd394c..0000000 --- a/BeakjoonOnlineJudge/1920/1920.cpp +++ /dev/null @@ -1,67 +0,0 @@ -/* -https://www.acmicpc.net/problem/1920 -BOJ 1920번 수 찾기 - -(1) 접근 -이진 탐색 문제이다. -이진 탐색 알고리즘이 어떤 것인지 간단히 정리하고 넘어가자면, -이진 탐색은 선형적인 탐색을 했을 때의 O(n제곱)의 수행시간을 O(logN)의 시간으로 줄이는 획기적인 알고리즘이다. 이진 탐색을 수행하기 위해서는 탐색의 대상인 데이터가 정렬된 상태이어야한다. 정렬된 상태의 데이터의 중앙값과 탐색할 값과 비교하여 크다면 큰값부터 끝까지, 작다면 처음부터 mid보다 작은값까지로 범위를 반으로 축소하여 이를 반복한다. - -(2) 해결 -이진탐색 알고리즘을 그대로 구현할 줄 안다면 쉽게 해결할 수 있다. -값을 입력받을 때마다 이진탐색 알고리즘을 통해 값이 존재하는지 존재하지 않는지를 체크한다. 그리고 그 결과에 따른 값을 각각 출력한다. - -(3) 주의사항 -iostream 대신 cstdio를 사용하여야한다. iosteam으로 인풋과 아웃풋을 구현하니 시간초과가 발생하였다. -*/ -#include -#include - -using namespace std; - -int N; -int M; -int A[100001]; -int B; - -bool findNumber(int num) -{ - int left = 0; - int right = N - 1; - - if(A[left] > num || A[right] < num) - return false; - - while (left <= right) - { - int mid = (left + right) / 2; - if(num < A[mid]) - right = mid - 1; - else if(num > A[mid]) - left = mid + 1; - else { - return true; - } - } - return false; -} - -int main() -{ - scanf("%d", &N); - for(int i = 0; i < N; i++) - { - scanf("%d", &A[i]); - } - sort(A,A+N); - - scanf("%d", &M); - for(int i = 0; i < M; i++) - { - scanf("%d", &B); - if(findNumber(B)) - printf("1\n"); - else printf("0\n"); - } - return 0; -} \ No newline at end of file diff --git a/BeakjoonOnlineJudge/1966/1966.cpp b/BeakjoonOnlineJudge/1966/1966.cpp deleted file mode 100644 index d1556e4..0000000 --- a/BeakjoonOnlineJudge/1966/1966.cpp +++ /dev/null @@ -1,79 +0,0 @@ -/* -https://www.acmicpc.net/problem/1966 -BOJ 1966번 프린터 큐 - -(1) 접근 -프린터의 예약된 작업을 큐 형식으로 저장한다. -하지만 큐의 맨 앞에 있는 작업의 중요도보다 높은 작업이 존재한다면 맨 앞의 작업을 pop하여 맨 뒤로 미룬다. 이 때 찾기를 원하는 순서의 작업이 몇 번째로 출력되는지 계산하는 문제이다. STL의 queue 자료구조를 이용하여 문제를 구현했다. - -(2) 해결 -입력받은 값들을 순서대로 큐에 입력한다. -다른 벡터에도 같은 순서로 값들을 입력한다. -벡터를 내림차순으로 정렬하여 중요도 순으로 정렬되도록 한다. -큐에서 작업을 수행할 떄마다 정렬된 벡터의 중요도와 비교하여 작업이 가능한지 체크한다. 가능한 작업이라면 큐에서 pop하고 count를 증가시킨다. -만약 원하는 순서의 작업이었다면 모든 반복을 중단시키고 count를 출력한다. -*/ - -#pragma warning(disable: 4996) -#include -#include -#include -#include -#include - -using namespace std; - -int N; -int M, findPrintNum; -int temp; -int ans; -int priorityMax; - -bool cmp(const pair &v1, const pair &v2) -{ - return v1.second > v2.second; -} - -int main() -{ - cin >> N; - for (int i = 0; i < N; i++) - { - ans = 0; - queue < pair > printQueue; - vector < pair > sortedQueue; - - cin >> M >> findPrintNum; - for (int j = 0; j < M; j++) - { - cin >> temp; - pair tempPair(j, temp); - printQueue.push(tempPair); - sortedQueue.push_back(tempPair); - } - - sort(sortedQueue.begin(), sortedQueue.end(), cmp); - - priorityMax = sortedQueue.front().second; - while (true) - { - if (priorityMax == printQueue.front().second) - { - ans++; - if (printQueue.front().first == findPrintNum) - break; - else - { - printQueue.pop(); - priorityMax = sortedQueue[ans].second; - } - } - else - { - printQueue.push(printQueue.front()); - printQueue.pop(); - } - } - cout << ans << endl; - } -} \ No newline at end of file diff --git a/BeakjoonOnlineJudge/1992/1992.cpp b/BeakjoonOnlineJudge/1992/1992.cpp deleted file mode 100644 index 6431151..0000000 --- a/BeakjoonOnlineJudge/1992/1992.cpp +++ /dev/null @@ -1,65 +0,0 @@ -/* -https://www.acmicpc.net/problem/1992 -BOJ 1992 쿼드트리 - -(1) 접근 -이전에 풀었던 '색종이 자르기' 문제와 같은 문제이다. -압축할 영상의 맨 처음 값과 다른 모든 값을 비교하여 같다면 처음 값을 그대로 출력하고, -다르다면 재귀함수를 이용하여 N을 2로 나누고 시작 지점을 지정하여 다시 반복시킨다. -'색종이 자르기 문제'와 다른점은 입력 방식이 문자열이라는 것과 출력 시 (,)을 사용해야하는 경우가 있다는 점이었다. - -(2) 해결 -문자열으로 입력을 받기 때문에 이를 파싱하여야 한다. -2중포문으로 x축, y축을 나누었고, y축이 바뀔때마다 해당 줄의 라인을 입력받아 x축 순서대로 넣어주었다. -출력 시에는 string을 반환하는 재귀함수를 만들어 처음과 끝에 (,)을 각각 붙여서 리턴하도록 했다. -(1)접근 에서 설명했듯이 한 덩어리가 다른 값을 가지고 있는 지 체크했다. 만약 다른 값을 가지고 있다면 4등분으로 나누어 다시 덩어리별로 다른 값을 가지고 있는지 체크하도록했다. 나눈 덩어리들의 결과에 '(', ')'을 붙여서 리턴받는다. 만약 덩어리의 모든 값이 같다면 그 값을 리턴한다. -*/ -#include -#include - -using namespace std; - -int N; -char video[64][64]; -string ans; - -string quadTree(int N, int startIndexY, int startIndexX) -{ - string resultVideo; - for(int i = startIndexY; i < startIndexY + N; i++) - { - for(int j = startIndexX; j < startIndexX + N; j++) - { - if(video[startIndexY][startIndexX] != video[i][j]) - { - resultVideo += "("; - resultVideo += quadTree(N / 2, startIndexY, startIndexX); - resultVideo += quadTree(N / 2, startIndexY, startIndexX + (N / 2)); - resultVideo += quadTree(N / 2, startIndexY+ (N / 2), startIndexX); - resultVideo += quadTree(N / 2, startIndexY+ (N / 2), startIndexX + (N / 2)); - resultVideo += ")"; - return resultVideo; - } - } - } - resultVideo = video[startIndexY][startIndexX]; - return resultVideo; -} - -int main() -{ - string videoStr; - cin >> N; - - for(int i = 0; i < N; i++) - { - cin >> videoStr; - for(int j = 0; j< N; j++) - { - video[i][j] = videoStr[j]; - } - } - - ans = quadTree(N, 0, 0); - cout << ans << "\n"; -} diff --git a/BeakjoonOnlineJudge/2004/2004.cpp b/BeakjoonOnlineJudge/2004/2004.cpp deleted file mode 100644 index d09fb5a..0000000 --- a/BeakjoonOnlineJudge/2004/2004.cpp +++ /dev/null @@ -1,57 +0,0 @@ -/* -https://www.acmicpc.net/problem/2004 -BOJ 2004번 조합 0의 개수 - -(1) 접근 -이항계수를 구하고 맨 뒤부터의 0의 개수를 구하는 문제이다. -이항 개수는 N!/M!(N-M)!으로 구할 수 있었다. - -(2) 해결 -팩토리얼 0의 개수 문제(BOJ 1676번)에서 0을 구하는 방법을 이용하여 이항개수 식 각 항의 0의 개수를 구하면 된다. -N!의 2와 5가 나오는 개수에서 M!, (N-M)!의 2와5가 나오는 개수를 합하여 뺄셈하면 된다. 여기서 주의할 점은 2가 나오는 개수와 5가 나오는 개수를 각각 따로 계산하여 이 식을 계산한 후 2의 개수와 5의 개수 중 더 작은 것을 정답으로 출력한다. -*/ -#include -#include - -using namespace std; - -long long int N , M; -int fiveCount; -int twoCount; -int zeroCount; - -int calFiveCount(int N) -{ - long long int five = 5; - long long int forReturn = 0; - while (N >= five) - { - forReturn += N / five; - five *= 5; - } - return forReturn; -} - -int calTwoCount(int N) -{ - long long int two = 2; - long long int forReturn = 0; - while (N >= two) - { - forReturn += N / two; - two *= 2; - } - return forReturn; -} - -int main() -{ - cin >> N >> M; - - fiveCount = calFiveCount(N) - (calFiveCount(M) + calFiveCount(N - M)); - twoCount = calTwoCount(N) - (calTwoCount(M) + calTwoCount(N - M)); - - zeroCount = (fiveCount > twoCount) ? twoCount : fiveCount; - cout << zeroCount; - return 0; -} \ No newline at end of file diff --git a/BeakjoonOnlineJudge/2164/2164.cpp b/BeakjoonOnlineJudge/2164/2164.cpp deleted file mode 100644 index 408a5aa..0000000 --- a/BeakjoonOnlineJudge/2164/2164.cpp +++ /dev/null @@ -1,37 +0,0 @@ -/* -https://www.acmicpc.net/problem/2164 -BOJ 2164번 카드2 - -(1) 접근 -1 부터 N까지의 카드를 1을 젤 위에 놓고 정렬한다. 맨 위의 카드를 1장 버린 후 다시 맨 위의 카드는 맨 아래에 놓는다. 이렇게 카드가 1장이 될 때까지 반복한다. -큐 자료구조를 사용하면 쉽게 해결할 수 있다. - -(2) 해결 -1 ~ N까지를 큐에 푸시한다. 큐에서 pop하고 큐의 front를 푸시한다. 이를 size가 1이 될 때까지 반복한다. -*/ -#include -#include -#include - -using namespace std; - -queue q; -int N; - -int main() -{ - cin >> N; - for(int i = 1; i <= N; i++) - { - q.push(i); - } - - while (q.size() > 1) - { - q.pop(); - q.push(q.front()); - q.pop(); - } - - cout << q.front(); -} \ No newline at end of file diff --git a/BeakjoonOnlineJudge/2360/2360.cpp b/BeakjoonOnlineJudge/2360/2360.cpp deleted file mode 100644 index ca81e82..0000000 --- a/BeakjoonOnlineJudge/2360/2360.cpp +++ /dev/null @@ -1,70 +0,0 @@ -/* -https://www.acmicpc.net/problem/2630 - -BOJ 2360번 색종이 만들기 - -(1) 접근 -정사각형으로 이루어진 정사각형 모양의 종이가 주어지고, 이는 하얀색 또는 파란색으로 색칠되어있다. -이 종이를 4등분하여 나누어진 부분이 모두 같은 색이 아니라면 나누어진 부분을 다시 4등분한다. 이를 더 이상 나누어질 수 없을 때까지 반복하고, 만약 같은 색이라면 1개의 사각형으로 더 이상 나누지 않는다. -결과적으로 하얀색, 파란색의 사각형 개수를 각각 출력하는 문제이다. -종이의 크기가 N x N이고 N은 2의 제곱수이므로 사각형을 나누는 과정을 재귀함수로 구현하여 큰 사각형이 점점 작은 사각형이 되도록 하였다. - -(2) 해결 -직관적으로 생각하여 사각형을 나누는 재귀함수를 만들었다. 가장 작은 정사각형이 될 때까지 나누고, 만약 가장 작은 정사각형 4개가 같은 색이라면 해당 색을 리턴하고, 만약 다른 색이라면 색 별로 총 색깔 개수에 더한다. -리턴받은 함수에서도 마찬가지로 리턴 받은 값들이 모두 같다면 해당 색을 리턴하고, 다르다면 이미 총 색깔개수에 포함되어 있기 때문에 이미 개수를 센 조각이라는 표시를 리턴한다. - -이렇게 재귀함수를 구현하니 재귀함수의 모양이 깔끔하지않았다. -그래서 블로그를 참조하여 다시 문제를 해결하였다. -결국 같은 조각을 표시되기 위해서는 옆 사각형과 색이 같아야한다.. -만약 아니라면 이를 기준으로 사각형을 나누고, 대칭이라면 조각의 개수를 카운트한다. -*/ -#include -using namespace std; - -int paperArray[128][128]; -int totalBlue = 0; -int totalWhite = 0; - -void dividePaper(int N, int startIndexY, int startIndexX) -{ - for (int i = startIndexY; i < startIndexY + N; i++) - { - for (int j = startIndexX; j < startIndexX + N; j++) - { - if (paperArray[startIndexY][startIndexX] != paperArray[i][j]) - { - int dividedN = N / 2; - dividePaper(dividedN, startIndexY, startIndexX); - dividePaper(dividedN, startIndexY, startIndexX + dividedN); - dividePaper(dividedN, startIndexY + dividedN, startIndexX); - dividePaper(dividedN, startIndexY + dividedN, startIndexX + dividedN); - return; - } - } - } - if (paperArray[startIndexY][startIndexX] == 0) - totalWhite++; - else totalBlue++; -} - -int main() -{ - ios_base::sync_with_stdio(false); - cin.tie(NULL); cout.tie(NULL); - - int N; - cin >> N; - - for (int i = 0; i < N; i++) - { - for (int j = 0; j < N; j++) - cin >> paperArray[i][j]; - } - - dividePaper(N, 0, 0); - - cout << totalWhite << "\n"; - cout << totalBlue << "\n"; - - return 0; -} \ No newline at end of file diff --git a/BeakjoonOnlineJudge/2606/2606.cpp b/BeakjoonOnlineJudge/2606/2606.cpp deleted file mode 100644 index 471958e..0000000 --- a/BeakjoonOnlineJudge/2606/2606.cpp +++ /dev/null @@ -1,58 +0,0 @@ -/* -https://www.acmicpc.net/problem/2606 - -BOJ 2606번 바이러스 - -(1) 접근 -1번 컴퓨터가 바이러스가 걸린다면 -연결된 컴퓨터들은 모두 바이러스에 감염된다. -1번 컴퓨터가 감염시킨 컴퓨터의 개수를 구하는 문제이다. -이는 DFS를 이용하면 쉽게 해결할 수 있다. - -(2) 해결 -기본적인 DFS를 사용하면 된다. -1번과 연결된 노드 중 방문되지 않은 노드가 있다면 count를 1 올려준다. 이를 연결된 노드로 이동하여 반복하면 모든 연결된 노드가 방문되었을 때 1번이 감염시킨 컴퓨터의 개수가 count에 저장된다. -*/ -#pragma warning(disable:4996) -#include -#include -#include - -using namespace std; - -int comCount; -int nodeCount; -vector com[101]; -bool isCheckedNode[101] = {false, }; -int infectionCount = 0; - -void DFS(int startNode) -{ - isCheckedNode[startNode] = true; - for (int i = 0; i < com[startNode].size(); i++) - { - int endNode = com[startNode][i]; - if (!isCheckedNode[endNode]) - { - infectionCount++; - DFS(endNode); - } - } -} - -int main() -{ - scanf("%d", &comCount); - scanf("%d", &nodeCount); - for (int i = 0; i < nodeCount; i++) - { - int startNode, endNode; - scanf("%d %d", &startNode, &endNode); - com[startNode].push_back(endNode); - com[endNode].push_back(startNode); - } - - DFS(1); - printf("%d", infectionCount); - return 0; -} \ No newline at end of file diff --git a/BeakjoonOnlineJudge/2740/2740.cpp b/BeakjoonOnlineJudge/2740/2740.cpp deleted file mode 100644 index 2dc2cde..0000000 --- a/BeakjoonOnlineJudge/2740/2740.cpp +++ /dev/null @@ -1,58 +0,0 @@ -/* -https://www.acmicpc.net/problem/2740 -BOJ 2740번 행렬곱 -(1) 접근 -행렬을 곱하는 문제이다. -행렬을 곱하는 방법을 그대로 구현하면 된다. -(2) 해결 -N * M 행렬과 M * K 행렬을 서로 곱하면 N * K의 행렬이 된다. -그러므로 행렬의 인덱스를 반복문을 이용하여 행렬 곱셈식 방법대로 각 행과 열의 곱셈결과를 더해주면 -행렬의 곱셈을 완료할 수 있다. -*/ -#include - -using namespace std; - -int N, M, K; -int A[100][100]; -int B[100][100]; -int ANS[100][100]; -int main() -{ - cin >> N >> M; - for(int i = 0; i < N; i++) - { - for(int j = 0; j < M; j++) - { - cin >> A[i][j]; - } - } - cin >> M >> K; - for(int i = 0; i < M; i++) - { - for(int j = 0; j < K; j++) - { - cin >> B[i][j]; - } - } - for(int i = 0; i < N; i++) - { - for(int j = 0; j < K; j++) - { - for(int k = 0; k < M; k++) - { - ANS[i][j] += A[i][k] * B[k][j]; - } - } - } - - for(int i = 0; i < N; i++) - { - for(int j = 0; j < K; j++) - { - cout << ANS[i][j] << " "; - } - cout << "\n"; - } - -} \ No newline at end of file diff --git a/BeakjoonOnlineJudge/2740/2740.swift b/BeakjoonOnlineJudge/2740/2740.swift deleted file mode 100644 index 74abe10..0000000 --- a/BeakjoonOnlineJudge/2740/2740.swift +++ /dev/null @@ -1,90 +0,0 @@ -/* -https://www.acmicpc.net/problem/2740 -BOJ 2740번 행렬곱 - -(1) 설명 -스위프트로 C++과 동일한 방식으로 구현하였다. -하지만 채점 방식의 입력과 문제가 발생하여 런타임에러가 난다. -알고리즘을 동일하게 구현했다는 것에 의의를 둔다. - -스위프트로 백준의 문제를 풀어본 적이 처음이기 때문에 -채점을 통과하지 못한 것이 아쉽지만, 스위프트를 조금 더 이해할 수 있었다. -*/ -import Foundation - -func input(_ A : inout Int, _ B : inout Int) -{ - let inputLine = readLine() - guard let _ = inputLine else { - return - } - let array = inputLine?.components(separatedBy: " ") - if let num = Int(array?[0] ?? "0") { - A = num - } - if let num = Int(array?[1] ?? "0") { - B = num - } -} - -func setMatrix(_ matrix : inout [[Int]], row : Int, column : Int) -{ - matrix = Array(repeating: Array(repeating: 0, count: column), count: row) - for i in 0.. [[Int]] -{ - var ans : [[Int]] = Array(repeating: Array(repeating: 0, count: N), count: K) - for i in 0.. -#include -#include - -using namespace std; - -int N; - -pair A; -pair B; - -int scoreA = 0; -int scoreB = 0; - -pair minusTime(pair pre, pair now) -{ - int sec = now.second - pre.second; - int min = now.first - pre.first; - if (sec < 0) - { - min--; - sec += 60; - } - pair calced(min, sec); - return calced; - -} - -pair plusTime(pair pre, pair now) -{ - int sec = now.second + pre.second; - int min = now.first + pre.first; - if (sec >= 60) - { - min++; - sec -= 60; - } - pair calced(min, sec); - return calced; -} - -string printTime(int time) -{ - if (time < 10) - return "0" + to_string(time); - else return to_string(time); -} - -int main() -{ - int scoredTeam; - string scoredTime; - int nowMin, nowSec; - pair preScoredTime(0, 0); - - cin >> N; - for (int i = 0; i < N + 1; i++) - { - if (i < N) - { - cin >> scoredTeam >> scoredTime; - nowMin = stoi(scoredTime.substr(0, 2)); - nowSec = stoi(scoredTime.substr(3, 2)); - } - else - { - nowMin = 48; - nowSec = 0; - } - - pair nowScoredTime(nowMin, nowSec); - - if (scoreA > scoreB) - A = plusTime(A, minusTime(preScoredTime, nowScoredTime)); - else if(scoreB > scoreA) - B = plusTime(B, minusTime(preScoredTime, nowScoredTime)); - - if (scoredTeam == 1) - scoreA++; - else scoreB++; - - preScoredTime = nowScoredTime; - } - - cout << printTime(A.first) << ":" << printTime(A.second) << endl; - cout << printTime(B.first) << ":" << printTime(B.second) << endl; -} \ No newline at end of file diff --git a/BeakjoonOnlineJudge/3036/3036.cpp b/BeakjoonOnlineJudge/3036/3036.cpp deleted file mode 100644 index a05e0ed..0000000 --- a/BeakjoonOnlineJudge/3036/3036.cpp +++ /dev/null @@ -1,48 +0,0 @@ -/* -https://www.acmicpc.net/problem/3036 - -BOJ 3036번 : 링 - -(1) 접근 -첫번째 원이 한 바퀴 회전할 때마다 인접한 원이 얼마나 회전 하는지를 파악하는 문제이다. -인접한 두 원의 비율만큼 인접한 원이 회전하게된다. - -(2) 해결 -인접한 두 원의 최대공약수를 이용하여 비율을 구하면 된다. -비율을 구한 후 앞의 원의 회전 수만큼 곱하면 된다. -이는 첫 번째 원과 n 번째 원의 비율과 같아지므로 결국 첫 번째원과 n 번쨰 원의 최대공약수를 구하여 비율을 구하면 된다. -*/ - -#pragma warning(disable: 4996) -#include - -using namespace std; - -int N; -int circle[101]; - -int GCD(int a, int b) -{ - if(b > a) - { - int temp = a; - a = b; - b = temp; - } - return (a % b == 0) ? b : GCD(b, a % b); -} - -int main() -{ - cin >> N; - for(int i = 0; i < N; i++) - { - cin >> circle[i]; - } - - for(int i = 1; i < N; i++) - { - int nowGDC = GCD(circle[0], circle[i]); - cout << circle[0]/nowGDC << "/" << circle[i]/nowGDC << endl; - } -} diff --git a/BeakjoonOnlineJudge/4949/4949.cpp b/BeakjoonOnlineJudge/4949/4949.cpp deleted file mode 100644 index 296ae9a..0000000 --- a/BeakjoonOnlineJudge/4949/4949.cpp +++ /dev/null @@ -1,77 +0,0 @@ -/* -https://www.acmicpc.net/problem/4949 -BOJ 4949번 균형잡힌 세상 - -(1) 접근 -괄호의 짝이 맞고, 괄호의 순서가 맞는지 체크하는 문제이다. -스택을 이용하여 문제를 해결할 수 있다. -문제를 잘못 읽어서 한참을 해메었다. 입력조건에서 '{', '}' 이 없다는 것과 마지막으로 '.'이 입력되었을 때도 yes를 출력하는 것으로 출력 조건을 이해하여 문제 해결 자체에는 문제가 없었음에도 시간을 너무 소비하게되었다. -다음부터는 문제를 확실하게 읽도록 하자! - -(2) 해결 -입력받은 문자열에서 괄호만 따로 저장한다. -괄호들을 for 반목문을 이용하여 하나하나 비교하며 열린 괄호 '(','['라면 스택에 푸시한다. 만약 닫힌 괄호가 등장했다면 스택의 탑과 비교하여 짝이 맞는지 체크한다. 예를들어 ')'가 등장했다면 스택의 탑에 '('이 있어야한다. '('이 있다면 pop을 하고, 다른 괄호가 있다면 false를 리턴한다. -또한 열린 괄호 또는 닫힌 괄호 더 많은 경우를 체크하여 false를 리턴한다. -*/ -#include -#include -#include - -using namespace std; - -string Text = ""; -string braket = ""; - - -bool check() -{ - // 괄호 조건을 체크하여 조건이 만족하는지 bool 변수로 리턴하는 함수 - vector stack; - - if (braket.length() == 0) // 괄호가 없는 경우도 짝이 맞는 것으로 한다. - return true; - - for (int i = 0; i < braket.length(); i++) - { - if (braket[i] == '(' || braket[i] == '[') // 열린 괄호라면 push - stack.push_back(braket[i]); - else if (stack.size() == 0) // 닫힌 괄호가 더 많은 경우 - return false; - else if (stack.back() == '(' && braket[i] != ')') // 짝이 맞지 않는 경우1 - return false; - else if (stack.back() == '[' && braket[i] != ']') // 짝이 맞지 않는 경우2 - return false; - else stack.pop_back(); // 짝이 맞는다면 pop - } - - if (stack.size() > 0) // 열린 괄호가 많은 경우 - return false; - - return true; -} - -int main() -{ - while (true) - { - getline(cin, Text); - - if (Text == ".") - break; - - // 입력 조건의 괄호만 따로 저장한다. - for (int i = 0; i < Text.length(); i++) - { - if (Text[i] == '(' || Text[i] == '[' - || Text[i] == ')' || Text[i] == ']') - braket += Text[i]; - } - - if (check()) - cout << "yes" << endl; - else cout << "no" << endl; - - braket = ""; - - } -} \ No newline at end of file diff --git a/BeakjoonOnlineJudge/5430/5430.cpp b/BeakjoonOnlineJudge/5430/5430.cpp deleted file mode 100644 index fd3095c..0000000 --- a/BeakjoonOnlineJudge/5430/5430.cpp +++ /dev/null @@ -1,113 +0,0 @@ -/* -https://www.acmicpc.net/problem/5430 -BOJ 5430번 AC - -(1) 접근 -문제에서 주어진 명령어를 입력받고, 명령어를 수행한 결과를 출력한 문제이다. -명령어는 배열의 가장 앞의 값을 삭제하거나, 배열의 순서를 뒤집는 것이 있다. -문제 특성 상 큐 또는 덱을 이용하면 쉽게 해결할 수 있을 것이고 보고 문제를 해결했다. - -(2) 해결 -문제를 읽자마자 명령어를 입력받을 때마다 순서를 뒤집거나 가장 앞의 값을 삭제하는 것을 직접 구현하여 문제해결을 했다. 하지만 문제 해결 시간이 1초 미만이므로 시간 초과가 발생했다. 배열의 순서를 뒤집는 명령어를 입력받는 경우 바로 순서를 변경하는 것이 아니었다. -이 명령어를 입력받으면 count를 1 추가했다. 그 count가 홀수인지 짝수인지를 판단하여 -홀수이면 순서가 뒤집어진 상태로, 짝수이면 입력받은 그대로의 상태로 보았다. 순서가 뒤집어진 상태에서 삭제 명령이 입력되면 가장 뒤의 값을 삭제하여 실제로 순서를 뒤집지 않고도 -수행할 수 있다. 이를 위해서 배열을 deque로 구현했다. 만약 삭제 시 이 deque가 비어있다면 error를 출력하고 남은 연산을 마무리한다. 마지막으로 출력 시 뒤집는 명령어의 개수count를 한번 더 체크하여 짝수라면 순서 그대로 출력하고, 홀수라면 거꾸로 출력한다. - -문제를 해결하면서 필요한 연산들을 함수로 나누고, 이 함수에서 for문을 사용하니까 시간초과에 걸리는 경우가 많았다. 시간이 촉박한 경우 for문이 최소화될 수 있도록 노력해야겠다. -*/ -#include -#include -#include -#include -#include - -using namespace std; - -deque numberPasser(string numbers) -{ - string temp = ""; - deque q; - for(int i = 1; i < numbers.length(); i++) - { - if((numbers[i] == ',' || numbers[i] == ']') && temp != "") - { - int num = stoi(temp); - q.push_back(num); - temp = ""; - } - else temp += numbers[i]; - } - return q; -} - -int main() -{ - cin.tie(0); - cin.sync_with_stdio(false); - - int T; - int N; - - cin >> T; - for(int i = 0; i < T; i++) - { - string commands; - string numbers; - int Rcount = 0; - bool isError = false; - deque numArray; - - cin >> commands; - cin >> N; - cin >> numbers; - - numArray = numberPasser(numbers); - - for (int j = 0; j < commands.length(); j++) - { - if (commands[j] == 'R') - { - Rcount++; - } - else if (commands[j] == 'D') - { - if (numArray.empty()) - { - isError = true; - cout << "error\n"; - break; - } - else if (Rcount % 2 == 0) - numArray.pop_front(); - else if (Rcount % 2 == 1) - numArray.pop_back(); - } - } - - if(!isError) - { - cout << "["; - if (Rcount % 2 == 0) - { - for (int j = 0; j < numArray.size(); j++) - { - cout << numArray[j]; - if (j < numArray.size() - 1) - cout << ","; - } - } - else - { - for (int j = numArray.size() - 1; j >= 0; j--) - { - cout << numArray[j]; - if (j > 0) - cout << ","; - } - } - cout << "]\n"; - } - } - - return 0; -} diff --git a/BeakjoonOnlineJudge/7579/7579.cpp b/BeakjoonOnlineJudge/7579/7579.cpp deleted file mode 100644 index 70cf159..0000000 --- a/BeakjoonOnlineJudge/7579/7579.cpp +++ /dev/null @@ -1,66 +0,0 @@ -/* -https://www.acmicpc.net/problem/7579 -BOJ 7579번 앱 - -(1) 접근 -냅색문제의 변형 문제이다. -어플을 실행할 때마다 메모리가 필요한데, 메모리는 제한되어 있어 동시에 실행할 수 있는 어플의 개수는 유한하다. -새로운 어플이 실행되어야 할때 메모리가 부족한 경우가 있는데, 이때 기존에 실행 중이던 어플을 비활성화시켜 메모리를 확보하여 실행한다. -하지만 비활성화시키는데도 비용이든다. 최소비용으로 새로운 어플을 실행하기 위한 메모리를 확보해야한다. - -(2) 해결 -작은 비용으로 더 많은 메모리를 확보해야한다. 따라서 비용을 기준으로 최대의 메모리를 가질 수 있는 경우를 메모제이션하여 해결한다. -현재 실행 중인 어플의 메모리와 비용을 입력받고, 해당 비용의 메모리를 메모제이션된 값과 비교시켜 더 큰 값을 다시 메모제이션한다. -메모제이션된 값들에 다음 차례의 어플의 비용을 더하다보면 모든 조합가능한 비용들을 계산할 수 있기 때문에 비용이 계산될 때마다 비교하여 큰 값을 저장한다. -마지막으로 메모제이션된 값 중 필요한 메모리인 M이상인 최소비용을 출력하면 된다. -*/ -#include -#include -#include - -using namespace std; - -int main() -{ - int N, M; - int memory[101] = {0, }; - int cost[101] = {0, }; - int DP[10001] = {0, }; - vector calculatedCost; - - scanf("%d %d", &N, &M); - for(int i = 0; i < N; i++) - { - scanf("%d", &memory[i]); - } - for(int i = 0; i < N; i++) - { - scanf("%d", &cost[i]); - } - - for(int i = 0; i < N; i++) - { - int preCal = calculatedCost.size(); - for(int j = preCal - 1; j >=0; j--) - { - if(DP[cost[i] + calculatedCost[j]] == 0) - calculatedCost.push_back(cost[i] + calculatedCost[j]); - DP[cost[i] + calculatedCost[j]] = max(DP[cost[i] + calculatedCost[j]], DP[calculatedCost[j]] + memory[i]); - } - - if(DP[cost[i]] == 0) - calculatedCost.push_back(cost[i]); - DP[cost[i]] = max(DP[cost[i]], memory[i]); - sort(calculatedCost.begin(), calculatedCost.end()); - } - - for(int i = 0; i < calculatedCost.size(); i++) - { - int index = calculatedCost[i]; - if(DP[index] >= M) - { - printf("%d\n", index); - break; - } - } -} diff --git a/BeakjoonOnlineJudge/9184/9184.cpp b/BeakjoonOnlineJudge/9184/9184.cpp deleted file mode 100644 index 1f38ff7..0000000 --- a/BeakjoonOnlineJudge/9184/9184.cpp +++ /dev/null @@ -1,66 +0,0 @@ -/* -https://www.acmicpc.net/problem/9184 -BOJ 9184번 신나는 함수 실행 - -(1) 접근 -재귀함수를 사용해서는 시간초과가 예상되는 문제였다. -문제의 조건에 맞도록 3차원 배열을 생성 후 다이나믹 프로그래밍으로 해결하였다. - -(2) 해결 -3차원 배열을 선언하였다. 문제 조건이 20보다 큰 수가 입력되는 경우 무조건 w(20,20,20)으로 계산하기 때문에 각 차원 별로 20씩 크기를 할당하면 된다. -문제 조건에 맞게 DP를 구하는 함수를 만들었고, for문을 이용하여 w(0, 0, 0) 부터 w(20, 20, 20)까지를 3차원 배열에 저장하였다. -이제 입력받은 수에 맞는 배열의 값을 출력하면 해결된다. -*/ -#include -#include - -using namespace std; - -int w[21][21][21] = {0, }; -int first, second, third; - -int calculateDP(int a, int b, int c) -{ - int aa = (a - 1 > 0) ? a - 1 : 0; - int bb = (b - 1 > 0) ? b - 1 : 0; - int cc = (c - 1 > 0) ? c - 1 : 0; - if(a <= 0 || b <= 0 || c <= 0) - return 1; - else if(a < b && b < c) - return w[a][b][cc] + w[a][bb][cc] - w[a][bb][c]; - else return w[aa][b][c] + w[aa][bb][c] + w[aa][b][cc] - w[aa][bb][cc]; -} - -void initDPSetting() -{ - for(int i = 1; i < 21; i++) - { - for(int j = 1; j < 21; j++) - { - for(int k = 1; k < 21; k++) - { - w[i][j][k] = calculateDP(i, j, k); - } - } - } -} - -int main() -{ - initDPSetting(); - while(true) - { - cin >> first >> second >> third; - if(first == -1 && second == -1 && third == -1) - break; - else - { - printf("w(%d, %d, %d) = ", first, second, third); - if(first <= 0 || second <= 0 || third <= 0) - cout << w[0][0][0] << endl; - else if(first > 20 || second > 20 || third > 20) - cout << w[20][20][20] << endl; - else cout << w[first][second][third] << endl; - } - } -} \ No newline at end of file diff --git a/BeakjoonOnlineJudge/9375/9375.cpp b/BeakjoonOnlineJudge/9375/9375.cpp deleted file mode 100644 index 27f753d..0000000 --- a/BeakjoonOnlineJudge/9375/9375.cpp +++ /dev/null @@ -1,54 +0,0 @@ -/* -https://www.acmicpc.net/problem/9375 -BOJ 9375번 패션왕 신해빈 - -(1) 접근 -의상의 종류와 개수에 따라서 만들 수 있는 조합을 구하는 공식을 구하고, -map 자료구조를 사용하여 해결할 수 있다. - -(2) 해결 -문제의 공식을 구하면 -(종류 별 의상 개수 + 1) * (종류 별 의상 개수 + 1) * ... * (종류 별 의상 개수 + 1) - 1 이다. -종류 key로 하여 map을 만들고 중복되는 키가 입력되었다면 key에 Hashing된 의상 개수를 1 증가시킨다. 중복되는 키가 없다면 새로운 키로 삽입한다. -*/ -#include -#include -#include -#include - -using namespace std; - -int N; -int M; -int cnt; -string temp; -string key; -map clothMap; - -int calFasionCount() -{ - for (map::iterator it = clothMap.begin(); it != clothMap.end(); it++) { - cnt = cnt * (it->second + 1); - } - return cnt - 1; -} - -int main() -{ - cin >> N; - for (int i = 0; i < N; i++) - { - cnt = 1; - clothMap.clear(); - cin >> M; - for (int j = 0; j < M; j++) - { - cin >> temp >> key; - if (clothMap.count(key)) - clothMap[key]++; - else - clothMap.insert(pair(key, 1) ); - } - cout << calFasionCount() << endl; - } -} \ No newline at end of file diff --git "a/Programmers/\354\213\234\354\240\200 \354\225\224\355\230\270/programmers#1.swift" "b/Programmers/\354\213\234\354\240\200 \354\225\224\355\230\270/programmers#1.swift" deleted file mode 100644 index 8349f7e..0000000 --- "a/Programmers/\354\213\234\354\240\200 \354\225\224\355\230\270/programmers#1.swift" +++ /dev/null @@ -1,34 +0,0 @@ -/* -프로그래머스 - 시저암호 (level 1) -스위프트에서는 문자와 아스키코드 간 변환을 위해서 string의 라이브러리와 -UnicodeScalar를 사용해야한다. -문제 자체는 간단하다. 문자가 밀리는 개수인 n을 알파벳의 개수인 26으로 나누고 그 나머지만큼 -알파벳에 더하면 된다. 이 때 소문자인지 대문자인지를 판별하여 시작점을 달리하면된다. -이렇게 변환된 문자의 아스키코드를 다시 문자열로 변환하여 정답 문자열에 추가한다. - -다른 사람들의 풀이를 보니 map 함수를 사용하는 경우가 많았다. -map에 대해서도 공부해보기로 하였다. -*/ -func solution(_ s:String, _ n:Int) -> String { - var answer : String - answer = "" - - for index in s - { - var sissorCode : UInt8 - if index.asciiValue! < UInt8(91) && index.asciiValue! > UInt8(64) { - sissorCode = UInt8(65) + (index.asciiValue! - UInt8(65) + UInt8(n)) % 26 - } - else if index.asciiValue! < UInt8(123) && index.asciiValue! > UInt8(96){ - sissorCode = UInt8(97) + (index.asciiValue! - UInt8(97) + UInt8(n)) % 26 - } - else { - sissorCode = index.asciiValue! - } - - let changedChar = String(UnicodeScalar(sissorCode)) - answer.append(changedChar) - } - - return answer -} \ No newline at end of file diff --git "a/Programmers/\355\201\254\353\240\210\354\235\270 \354\235\270\355\230\225 \353\275\221\352\270\260 \352\262\214\354\236\204/programmers#2.swift" "b/Programmers/\355\201\254\353\240\210\354\235\270 \354\235\270\355\230\225 \353\275\221\352\270\260 \352\262\214\354\236\204/programmers#2.swift" deleted file mode 100644 index 5fd1f2e..0000000 --- "a/Programmers/\355\201\254\353\240\210\354\235\270 \354\235\270\355\230\225 \353\275\221\352\270\260 \352\262\214\354\236\204/programmers#2.swift" +++ /dev/null @@ -1,63 +0,0 @@ -/* -프로그래머스 - 크레인 인형 뽑기 게임 (level 1) -2차원 Array로 표현된 데이터를 해석하여 원하는 결과를 얻어야하는 문제이다. - -인형 뽑기 통이 2차원 배열로 표현되고, 인형의 종류가 2차원 배열의 정수로 표현된다. -쌓여있는 인형들을 주어진 순서대로 뽑아 바구니로 옮기고, 바구니로 옮겨진 인형 중 2개가 붙어 있는 것이 -있다면 그 인형 2개는 사라진다. 이때 사라진 인형의 개수를 구하는 문제이다. - -2차원 배열을 arr[i][j]로 표현한다면 뽑아야 할 줄의 번호를 j로 고정시킨 후, i값을 비교하여 -0이 아닌 수를 찾고, 이 수가 있다면 바구니로 옮기고 0으로 바꾼다. -바구니로 옮겨지면 바구니의 맨 위의 2개를 비교하여 같다면 삭제하고, 다르다면 다음 수를 뽑기 위해 크레인을 이동한다. -*/ -import Foundation - -func solution(_ board:[[Int]], _ moves:[Int]) -> Int { - var remain = board - var moved : [Int] = [] - var answer : Int = 0 - - for index in moves - { - let boardNum = index - 1 - let dollIndex = findDoll(remain, boardNum) - - if dollIndex == -1 { - continue - } - - moved.append(remain[dollIndex][boardNum]) - remain[dollIndex][boardNum] = 0 - - if moved.count >= 2 { - answer += checkMovedDoll(&moved) - } - - - } - return answer -} - -func findDoll(_ list : [[Int]], _ index : Int) -> Int -{ - - let count = list.count - for i in 0.. Int -{ - if list[list.count - 1] == list[list.count - 2] - { - list.remove(at : list.count - 1) - list.remove(at : list.count - 1) - return 2 - } - return 0 -} diff --git a/README.md b/README.md index eab6753..061ff81 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,2 @@ -# Algorithm Study -
- -> **공부할 내용** ->> **Algorithm**
->> : 알고리즘을 공부하고 내용을 정리합니다.
->> **BeakjoonOnlineJudge**
->> : 백준 온라인 저지 문제 풀이
- -## 참고 -* 책 - - 쉽게 배우는 알고리즘 : 관계 중심의 사고법, 문병로 저 -* 사이트 - - [백준 온라인 저지](https://www.acmicpc.net/) \ No newline at end of file +# Algorithm +Algorithm Study