diff --git a/baekjoon/.clang-format b/baekjoon/.clang-format new file mode 100644 index 0000000..880cdc7 --- /dev/null +++ b/baekjoon/.clang-format @@ -0,0 +1,2 @@ +BasedOnStyle: Google +ColumnLimit: 0 diff --git a/baekjoon/.editorconfig b/baekjoon/.editorconfig new file mode 100644 index 0000000..1f929a6 --- /dev/null +++ b/baekjoon/.editorconfig @@ -0,0 +1,12 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +insert_final_newline = true +indent_style = space +indent_size = 2 +trim_trailing_whitespace = true + +[*.{cpp, c, h}] +max_line_length = 0 diff --git a/baekjoon/.github/workflows/SyntaxCheck.yaml b/baekjoon/.github/workflows/SyntaxCheck.yaml new file mode 100644 index 0000000..0421afa --- /dev/null +++ b/baekjoon/.github/workflows/SyntaxCheck.yaml @@ -0,0 +1,32 @@ +name: SyntaxCheck + +on: + push: + branches: [main] + paths: # SyntaxCheck runs only when .c .cpp .h files are changed. + - "**.c" + - "**.cpp" + - "**.h" + + pull_request: + branches: [main] + paths: # SyntaxCheck runs only when .c .cpp .h files are changed. + - "**.c" + - "**.cpp" + - "**.h" + +jobs: + SyntaxCheck: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Install clang-format + run: sudo apt-get install -y clang-format + + - name: Check clang-format + run: clang-format -n -Werror $(find . -regex '.*\.\(c\|cpp\|h\)') + # Use 'clang-format -h' on linux for help manuals. + # '-Werror' option turns warnings into errors. diff --git a/baekjoon/.gitignore b/baekjoon/.gitignore new file mode 100644 index 0000000..732169a --- /dev/null +++ b/baekjoon/.gitignore @@ -0,0 +1,2 @@ +# Ignore output(.exe) files +Src/**/Output diff --git a/baekjoon/.vscode/settings.json b/baekjoon/.vscode/settings.json new file mode 100644 index 0000000..7a17d1a --- /dev/null +++ b/baekjoon/.vscode/settings.json @@ -0,0 +1,9 @@ +{ + // Editor: VScode + "editor.formatOnPaste": true, + "editor.formatOnType": true, + "editor.formatOnSave": true, + // Extension: C/C++ Extension Pack (clang-format) + "C_Cpp.clang_format_fallbackStyle": "Google", + "C_Cpp.errorSquiggles": "disabled" +} \ No newline at end of file diff --git a/baekjoon/README.md b/baekjoon/README.md new file mode 100644 index 0000000..f1c681b --- /dev/null +++ b/baekjoon/README.md @@ -0,0 +1,110 @@ +# 1. Introduction + +- 백준(Baekjoon), 프로그래머스(Programmers) 등 Problem Solving(이하 PS)을 하며 생성된 소스 코드들을 효율적으로 관리하기 위해 고안된 프레임워크입니다. +- C/C++ 언어 사용자들을 대상으로 합니다. + +## 1-1. Reasons for selecting VScode + +### 1-1-1. PS만을 위한 가벼운 에디터(Editor)의 필요성. + +- C 계열 언어의 개발이 주로 이루어지는 Visual Studio는 통합 IDE로써 프로그램이 무겁고 복잡합니다. 이를 단순 PS만을 위해 사용하기에는 부담이 따릅니다. + +### 1-1-2. 라이브러리(Library)를 제외한 의존성 관계의 불필요성. + +- 일반적인 개발의 경우, 다양한 파일 및 소스코드들의 의존성 관계를 관리하며 빌드(Build)를 진행합니다. 이를 C 계열 언어에서 효율적으로 수행하기 위해서는 Visual Studio가 최적이라 할 수 있습니다. +- 하지만, PS의 경우, 각각의 소스코드들이 독립적입니다. 각각의 소스코드 내부에서 사용되는 라이브러리(Library)들에는 의존적일 수 있지만, 이외의 파일에는 의존적이지 않습니다. +- 예를 들어, Visual Studio에서 C/C++ 프로젝트를 시작하게 되면, 외부종속성 및 리소스 등을 관리하기 위한 수많은 부가 파일들이 생성됩니다. 이는 단순 PS만을 위한 환경으로는 과합니다. + +## 1-2. Shortcomings of VScode + +### 1-2-1. 컴파일러의 부재 및 다소 복잡한 설치 과정. + +- Visual Studio와는 달리, VScode에는 C/C++ Compiler가 내장되어 있지 않습니다. Extension을 통한 확장 설치도 불가능합니다. 따라서, 운영체제에 따라 컴파일러를 개별 설치해 주거나 기존에 설치되어 있는 컴파일러를 이용해야 합니다. +- 하지만, 이 과정이 다소 복잡합니다. 일반적인 방법으로 VScode에서 컴파일러를 사용하기 위해서는 tasks.json 파일을 수정하여 컴파일 및 빌드 관련 내용들을 설정해야 합니다. 생각보다 복잡한 과정에 어려움을 겪는 사람들이 많습니다. +- 따라서, 'C/C++ Compile Run'이라는 VScode Extension을 통해 일관된 방식으로 컴파일러를 설치 및 실행할 수 있게 하였습니다. 이는 기존 방식보다 쉽고 편리합니다. + +### 1-2-2. 일관된 Convention(Linter or Formatter)의 필요성. + +- Visual Studio의 경우 IDE에서 자동으로 Convention을 맞춰줍니다. 하지만, VScode는 단순 에디터이기 때문에 아무런 기능이 없습니다. 'C/C++ Extension Pack'이라는 VScode Extension을 설치하면 자동적으로 'clang-format'이라는 Formatter가 함께 설치됩니다. 이는 C/C++ 언어를 위한 Linter 혹은 Formatter라 할 수 있습니다. 'clang-format'을 통해 일관된 Convention을 유지할 수 있게 하였습니다. +- 또한, 'editorconfig'를 통해 보다 전역적인 Convention을 유지할 수 있게 하였습니다. + +### 1-2-3. CI/CD 과정의 필요성. + +- 문법 및 Convention 오류가 있는 소스코드가 업로드된다면 문제가 될 수 있습니다. 이를 Github Workflows를 통해 자동으로 관리합니다. c, cpp, h 확장자를 가진 파일을 수정 및 추가한 후 Push 및 Pull_Request를 진행할 경우, 자동으로 문법 및 Convention을 검사한 후 CI/CD 과정을 수행합니다. + +### 1-2-4. IDE와 유사한 환경 구성의 필요성. + +- 결국, Visual Studio의 장점과 VScode의 장점을 합치기 위해 현재 프레임워크를 설계하였습니다. Visual Studio처럼 편리하면서 가볍고 확장 가능한 VScode 개발환경을 만드는 것이 목표입니다. + +# 2. How to install + +## 2-1. Prerequisite + +### 2-1-1. Git + +- Git을 설치해야 합니다. + +### 2-1-2. VScode + +- VScode를 설치해야 합니다. + +### 2-1-3. VScode Extension & C/C++ Compiler + +- 아래 Extesion 및 Compiler를 VScode 상에 모두 설치합니다. + +1. C/C++ Extension Pack + +2. C/C++ Compile Run & TDM-GCC(Compiler) + + > 'C/C++ Compile Run' Extension을 설치한 후, 해당 Extension의 Manual에 따라 TDM-GCC를 설치합니다. + > + > C Compiler의 기본 경로 + > + > - /usr/bin/gcc (Linux) + > - C:\TDM-GCC-64\bin\gcc.exe (Windows) + > + > C++ Compiler의 기본 경로 + > + > - /usr/bin/g++ (Linux) + > - C:\TDM-GCC-64\bin\gcc.exe (Windows) + +3. EditorConfig for VS Code + +## 2-2. git clone + +Git Bash 상에 아래 명령어를 입력합니다. + +```bash +git clone https://github.com/lumirlumir/PS_Framework.git +``` + +# 3. File Structures + +```bash +📦PS_Framework + ┣ 📂.github + ┃ ┗ 📂workflows + ┃ ┗ 📜SyntaxCheck.yaml # Git: Github Workflows 설정 파일. + ┣ 📂.vscode + ┃ ┗ 📜settings.json # VScode: Editor 설정 파일. + ┣ 📂Src + ┃ ┗ 📂* (Baekjoon, Programmers or Etc.) + ┃ ┣ 📂Blogged # 블로그에 게시된 문제 저장. + ┃ ┣ 📂Solved # 다 푼 문제 저장. + ┃ ┗ 📂Unsolved # 아직 풀고있는 문제 저장. + ┣ 📜.clang-format # C/C++: Convention 설정 파일. + ┣ 📜.editorconfig # EditorConfig: Covention 설정 파일. + ┣ 📜.gitignore # Git: Gitignore 설정 파일. + ┣ 📜README.md # Git: README 파일. + ┗ 📜VScode.code-workspace # VScode: Workspace 설정 파일. +``` + +# 4. Others + +## 4-1. Blog에 Repository상의 소스코드를 삽입하는 방법. + +- [Emgithub](https://emgithub.com/) + +# 5. Release Note + +- v0.0.1: 2024.02.20 diff --git a/baekjoon/Src/Baekjoon/Blogged/.gitkeep b/baekjoon/Src/Baekjoon/Blogged/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/baekjoon/Src/Baekjoon/Solved/1000.cpp b/baekjoon/Src/Baekjoon/Solved/1000.cpp new file mode 100644 index 0000000..2c420ac --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/1000.cpp @@ -0,0 +1,8 @@ +#include + +int main(void) { + int A, B; + scanf("%d %d", &A, &B); + printf("%d", A + B); + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/1001.cpp b/baekjoon/Src/Baekjoon/Solved/1001.cpp new file mode 100644 index 0000000..426fbb4 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/1001.cpp @@ -0,0 +1,10 @@ +#include + +int main(void) { + int A, B, result = 0; + + scanf("%d %d", &A, &B); + + printf("%d", A - B); + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/1002.cpp b/baekjoon/Src/Baekjoon/Solved/1002.cpp new file mode 100644 index 0000000..0627b46 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/1002.cpp @@ -0,0 +1,57 @@ +#pragma warning(disable : 4996) // visual studio scanf 오류 방지. +#include //수학함수 사용 목적. +#include +#include //abs() 함수 사용 목적. + +typedef struct { + int x; // x좌표 + int y; // y좌표 + int r; // 반지름 +} Circle; + +double center_distance(Circle c1, Circle c2) { + return sqrt(pow(c1.x - c2.x, 2) + pow(c1.y - c2.y, 2)); +} + +int positional_relationship(Circle c1, Circle c2) { + double d = center_distance(c1, c2); // 자료형이 double임에 주의. + + /* 1. 두 원이 일치할 때 */ + if (c1.x == c2.x && c1.y == c2.y && c1.r == c2.r) { + return -1; + } + /* 2. 두 원이 일치하지 않을 때 */ + else { + /* 2-1. 외부 = 접점 0개 */ + if (c1.r + c2.r < d) + return 0; + /* 2-2. 외접 = 접점 1개 */ + else if (c1.r + c2.r == d) + return 1; + /* 2-3. 두점에서 만남 = 접점 2개 */ + else if (abs(c1.r - c2.r) < d && d < c1.r + c2.r) + return 2; + /* 2-4. 내접 = 접점 1개 */ + else if (abs(c1.r - c2.r) == d) + return 1; + /* 2-5. 내부 = 접점 0개 */ + else if (d < abs(c1.r - c2.r)) + return 0; + /* 2-6. 동심원 = 접점 0개 */ + else if (d == 0) + return 0; + } +} + +int main(int argc, char* argv[]) { + int T; + Circle c1, c2; + + scanf("%d", &T); + for (int i = 0; i < T; i++) { + scanf("%d %d %d %d %d %d", &c1.x, &c1.y, &c1.r, &c2.x, &c2.y, &c2.r); + + printf("%d\n", positional_relationship(c1, c2)); + } + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/1003[DP]_BU.cpp b/baekjoon/Src/Baekjoon/Solved/1003[DP]_BU.cpp new file mode 100644 index 0000000..d1ac72e --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/1003[DP]_BU.cpp @@ -0,0 +1,36 @@ +#pragma warning(disable : 4996) +#include + +typedef struct { + int num0_cache; + int num1_cache; +} Cache; + +Cache C[41] = {{1, 0}, {0, 1}, {}}; +// Cache(Memoization), C[0] C[1] 0 ʱȭ. + +void fibonacci(void) { + for (int i = 2; i <= 40; i++) { // 40 ۰ų ڿ + C[i].num0_cache = C[i - 1].num0_cache + C[i - 2].num0_cache; + C[i].num1_cache = C[i - 1].num1_cache + C[i - 2].num1_cache; + } +} + +int main(int argc, char* argv[]) { + fibonacci(); + + int T; + scanf("%d", &T); + for (int i = 0; i < T; i++) { + int N; + scanf("%d", &N); + printf("%d %d\n", C[N].num0_cache, C[N].num1_cache); + } + + return 0; +} + +/* + Ȳ TDİ BU ߿ ɷ Ǯ + ˾ƾ Ѵ. +*/ diff --git a/baekjoon/Src/Baekjoon/Solved/1008.cpp b/baekjoon/Src/Baekjoon/Solved/1008.cpp new file mode 100644 index 0000000..67d8dd0 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/1008.cpp @@ -0,0 +1,12 @@ +#include +#include +using namespace std; + +int main(void) { + int A, B; + cin >> A >> B; + + printf("%0.10lf", ((double)A / (double)B)); + + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/1009.cpp b/baekjoon/Src/Baekjoon/Solved/1009.cpp new file mode 100644 index 0000000..03b3a84 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/1009.cpp @@ -0,0 +1,40 @@ +#pragma warning(disable : 4996) // visual studio scanf 오류 방지. +#include + +int table[10][4]; + +int power(int a, int b) { + if (b == 0) + return 1; + else + return power(a, b - 1) * a; +} + +void make_table(void) { + for (int i = 0; i < 10; i++) + for (int j = 1; j <= 4; j++) + table[i][j % 4] = (int)power(i, j) % 10; + /* + math.h의 pow()를 이용하여, + table[i][j % 4] = (int)pow(i, j) % 10; + 으로 구현해도 된다. + (math.h 함수는 반환형이 double이므로, int로 형변환 해준다.) + */ +} + +int main(int argc, char* argv[]) { + /* 변수선언 */ + int a, b, T; + + /* 테이블 만들기 */ + make_table(); + + /* 입력값 받은 후 연산 */ + scanf("%d", &T); + for (int i = 0; i < T; i++) { + scanf("%d %d", &a, &b); + printf("%d\n", table[a % 10][b % 4] == 0 ? 10 : table[a % 10][b % 4]); + } + + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/10090.cpp b/baekjoon/Src/Baekjoon/Solved/10090.cpp new file mode 100644 index 0000000..0cc3a00 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/10090.cpp @@ -0,0 +1,77 @@ +#pragma warning(disable : 4996) +#include +#include +#include +#include +using namespace std; + +void merge_sort(int A[], int n); +void merge_sort(int A[], int tmp[], int start, int end); +void merge_sort_merge(int A[], int tmp[], int start, int mid, int end); +void print_test(int* A, int n); + +long long countcount = 0; + +int main(int argc, char* argv[]) { + int n = 0; + scanf("%d", &n); + + int* A = (int*)calloc(n, sizeof(int)); // val 랜덤, idx 오름차순 + for (int i = 0; i < n; i++) { + scanf("%d", &A[i]); + } + + // print_test(A, n);//Test + + merge_sort(A, n); + + // print_test(A, n);//Test + + printf("%lld", countcount); + + return 0; +} + +void merge_sort(int A[], int n) { + int* tmp = (int*)calloc(n, sizeof(int)); + merge_sort(A, tmp, 0, n - 1); +} + +void merge_sort(int A[], int tmp[], int start, int end) { + if (start < end) { + int mid = (start + end) / 2; + merge_sort(A, tmp, start, mid); // 배열의 앞부분 + merge_sort(A, tmp, mid + 1, end); // 배열의 뒷부분 + merge_sort_merge(A, tmp, start, mid, end); // 배열방이 1개 남았을때 되돌아옴. + } +} + +void merge_sort_merge(int A[], int tmp[], int start, int mid, int end) { + for (int i = start; i <= end; i++) { // 배열복사 + tmp[i] = A[i]; + } + int part1idx = start; + int part2idx = mid + 1; + int idx = start; + + while (part1idx <= mid && part2idx <= end) { + if (tmp[part1idx] <= tmp[part2idx]) { + A[idx] = tmp[part1idx]; + part1idx++; + } else { + A[idx] = tmp[part2idx]; + part2idx++; + countcount += (mid - part1idx + 1); + } + idx++; + } + for (int i = 0; i <= mid - part1idx; i++) { // part1남은 데이터 정리.(뒤쪽데이터는 상관 없음.) + A[idx + i] = tmp[part1idx + i]; + } +} + +void print_test(int* A, int n) { + for (int i = 0; i < n; ++i) + printf("[%d]=%2d\n", i, A[i]); + printf("\n"); +} diff --git a/baekjoon/Src/Baekjoon/Solved/1011[MATH].cpp b/baekjoon/Src/Baekjoon/Solved/1011[MATH].cpp new file mode 100644 index 0000000..5aae37b --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/1011[MATH].cpp @@ -0,0 +1,25 @@ +#pragma warning(disable : 4996) +#include +#include +using namespace std; + +int main(int argc, char* argv[]) { + /* Input */ + int T; + scanf("%d", &T); + + for (int i = 0; i < T; i++) { + /* Input */ + int x, y; + scanf("%d %d", &x, &y); + int dist = y - x; + + printf("%d\n", (int)ceil(2 * sqrt(dist) - 1)); + } + + return 0; +} + +/* +̿ Ǯ . ȭĸóؼ Ʈ ȭ鿡 Ƶ. +*/ diff --git a/baekjoon/Src/Baekjoon/Solved/1012[Graph].cpp b/baekjoon/Src/Baekjoon/Solved/1012[Graph].cpp new file mode 100644 index 0000000..e0999ab --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/1012[Graph].cpp @@ -0,0 +1,71 @@ +#include +#include +#include +#include +using namespace std; + +int main(int argc, char* argv[]) { + /* Faster */ + ios::sync_with_stdio(0); + cin.tie(0); + cout.tie(0); + + /* Init */ // ¿ + int dx[4] = {0, 0, -1, 1}; + int dy[4] = {-1, 1, 0, 0}; + + /* Input */ + int t; + cin >> t; + + /* BFS */ + while (t--) { + /* Init */ + queue> q; // + int ans = 0; + + /* Input */ + int m, n, k; + cin >> m >> n >> k; + + vector> map(n, vector(m)); + for (int i = 0; i < k; i++) { + int x, y; + cin >> x >> y; + map[y][x] = 1; + } + + /* BFS */ + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + if (map[i][j] == 1) { + q.push(make_pair(i, j)); // + ans++; + } + + while (!q.empty()) { + int px = q.front().second; + int py = q.front().first; + q.pop(); + + for (int l = 0; l < 4; l++) { + int nx = px + dx[l]; + int ny = py + dy[l]; + + if (0 <= nx && nx < m && 0 <= ny && ny < n) + if (map[ny][nx] == 1) { + q.push(make_pair(ny, nx)); + map[ny][nx] = 0; + } + } + } + } + } + + /* Output */ + cout << ans << '\n'; + } + + /* Return */ + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/10171.cpp b/baekjoon/Src/Baekjoon/Solved/10171.cpp new file mode 100644 index 0000000..b544259 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/10171.cpp @@ -0,0 +1,12 @@ +#include +using std::cin; +using std::cout; +using std::endl; + +int main(void) { + cout << "\\ /\\" << endl; + cout << " ) ( \')" << endl; + cout << "( / )" << endl; + cout << " \\(__)|" << endl; + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/10172.cpp b/baekjoon/Src/Baekjoon/Solved/10172.cpp new file mode 100644 index 0000000..2ee1b7a --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/10172.cpp @@ -0,0 +1,11 @@ +#include + +int main(void) { + printf("|\\_/|\n"); + printf("|q p| /}\n"); + printf("( 0 )\"\"\"\\\n"); + printf("|\"^\"` |\n"); + printf("||_/=\\\\__|"); + + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/1018.cpp b/baekjoon/Src/Baekjoon/Solved/1018.cpp new file mode 100644 index 0000000..9f8ed6b --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/1018.cpp @@ -0,0 +1,63 @@ +#pragma warning(disable : 4996) + +#include // 최댓값, 최솟값 정의. +#include +#include + +#define min(a, b) (((a) > (b)) ? (b) : (a)) + +int main(int argc, char* argv[]) { + /* Input */ + int N, M; + scanf("%d %d", &N, &M); // N은 세로, M은 가로. + getchar(); //'\n'을 입력버퍼에서 지움. + + /* 2차원 배열 동적할당 */ + char** arr = (char**)calloc(N, sizeof(char*)); + for (int i = 0; i < N; i++) + arr[i] = (char*)calloc(M + 2, sizeof(char)); //'\n'과 '\0' 고려. + + /* Input */ + for (int i = 0; i < N; i++) + fgets(arr[i], (M + 2) * sizeof(char), stdin); + // sizeof(arr[i])를 하면, arr[i] = int형 싱글 포인터 크기인 8이 반환된다. + + /* 체스판 체크 */ + int min_num = INT_MAX; + + for (int col = 0; col <= N - 8; col++) { + for (int row = 0; row <= M - 8; row++) { + int W_start = 0, B_start = 0; + + /* 8 x 8 크기의 체스판 체크 */ + for (int i = col; i < col + 8; i++) { + for (int j = row; j < row + 8; j++) { + /* 세로+가로 인덱스 짝수 */ + if ((i + j) % 2 == 0) { + if (arr[i][j] != 'W') W_start++; + if (arr[i][j] != 'B') B_start++; + + } + + /* 세로+가로 인덱스 홀수 */ + else if ((i + j) % 2 == 1) { + if (arr[i][j] != 'B') W_start++; + if (arr[i][j] != 'W') B_start++; + } + } + } + + min_num = min(min_num, min(W_start, B_start)); + } + } + + /* 출력 */ + printf("%d", min_num); + + /* 마무리 */ + for (int i = 0; i < N; i++) + free(arr[i]); + free(arr); + + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/1021.cpp b/baekjoon/Src/Baekjoon/Solved/1021.cpp new file mode 100644 index 0000000..396a164 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/1021.cpp @@ -0,0 +1,49 @@ +#include +#include +#include +using namespace std; + +int main(int argc, char* argv[]) { + /* Faster */ + ios::sync_with_stdio(0); + cin.tie(0); + cout.tie(0); + + /* Init */ + deque dq; + int count = 0; + + /* Input */ + int n, m; + cin >> n >> m; + + for (int i = 1; i <= n; i++) // deque 1 N ڿ . + dq.push_back(i); + + /* Calculation */ + while (m--) { + /* Init */ + int lr = 0; // 2( ̵, Left Rotation) Ƚ + int a; + cin >> a; + + /* Calculation */ + while (true) { + if (dq.front() == a) { + dq.pop_front(); + break; + } else { + dq.push_back(dq.front()); + dq.pop_front(); + lr++; + } + } + count += min(lr, (int)dq.size() + 1 - lr); + } + + /* Output */ + cout << count; + + /* Return */ + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/10430.cpp b/baekjoon/Src/Baekjoon/Solved/10430.cpp new file mode 100644 index 0000000..0133e3b --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/10430.cpp @@ -0,0 +1,13 @@ +#pragma warning(disable : 4996) +#include +#include + +int main(void) { + int A, B, C = 0; + + scanf("%d %d %d", &A, &B, &C); + + printf("%d\n%d\n%d\n%d", (A + B) % C, ((A % C) + (B % C)) % C, (A * B) % C, ((A % C) * (B % C)) % C); + + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/1049[GR].cpp b/baekjoon/Src/Baekjoon/Solved/1049[GR].cpp new file mode 100644 index 0000000..92908a3 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/1049[GR].cpp @@ -0,0 +1,45 @@ +#pragma warning(disable : 4996) +#include +#include +#include +using namespace std; + +int find_min(int arr[], int len) { + int min = INT_MAX; + + for (int i = 0; i < len; i++) + if (min > arr[i]) min = arr[i]; + + return min; +} + +int main(int argc, char* argv[]) { + /* Input */ + int N, M; + scanf("%d %d", &N, &M); + int* rem = new int[M * 2]{}; // = + int* quo = new int[M * 2]{}; // Ű = + + /* Calculation */ + for (int i = 0; i < M; i++) { + /* Input */ + int p, s; + scanf("%d %d", &p, &s); // p=package, s=single + + /* = */ + rem[2 * i] = p; + rem[2 * i + 1] = s * (N % 6); + + /* Ű = */ + quo[2 * i] = p * (N / 6); + quo[2 * i + 1] = s * (N / 6) * 6; + } + + /* OUtput */ + printf("%d", find_min(rem, M * 2) + find_min(quo, M * 2)); + + /* End */ + delete[] rem; + delete[] quo; + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/1065.cpp b/baekjoon/Src/Baekjoon/Solved/1065.cpp new file mode 100644 index 0000000..12a4ced --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/1065.cpp @@ -0,0 +1,19 @@ +#pragma warning(disable : 4996) +#include +#include + +int main(void) { + int N = 0; + int count = 0; + scanf("%d", &N); + + for (int i = 1; i <= N; i++) { + if (1 <= i && i <= 99) + count++; + else if (((i / 100) - (i / 10) % 10) == ((i / 10) % 10 - (i % 10))) + count++; + } + printf("%d", count); + + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/10718.cpp b/baekjoon/Src/Baekjoon/Solved/10718.cpp new file mode 100644 index 0000000..a2ca854 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/10718.cpp @@ -0,0 +1,6 @@ +#include + +int main(void) { + printf("강한친구 대한육군\n강한친구 대한육군"); + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/10773.cpp b/baekjoon/Src/Baekjoon/Solved/10773.cpp new file mode 100644 index 0000000..db5d2ff --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/10773.cpp @@ -0,0 +1,26 @@ +#pragma warning(disable : 4996) +#include +#include + +#include +using namespace std; +int main(void) { + int n, tmp, sum = 0; + stack stack; + + scanf("%d", &n); + for (int i = 0; i < n; i++) { + scanf("%d", &tmp); + if (tmp != 0) + stack.push(tmp); + else + stack.pop(); + } + while (!stack.empty()) { + sum += stack.top(); + stack.pop(); + } + printf("%d", sum); + + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/10807.cpp b/baekjoon/Src/Baekjoon/Solved/10807.cpp new file mode 100644 index 0000000..483ee75 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/10807.cpp @@ -0,0 +1,31 @@ +#pragma warning(disable : 4996) +#include +#include //동적배열 사용목적 + +int main(int argc, char* argv[]) { + /* N값 입력받기 */ + int N; + scanf("%d", &N); + + /* N개의 정수를 동적배열에 입력받기 */ + int* arr = (int*)calloc(N, sizeof(int)); + for (int i = 0; i < N; i++) + scanf("%d", &arr[i]); + + /* v값 입력받기 */ + int v; + scanf("%d", &v); + + /* 배열에서 v값의 개수 찾기 */ + int count = 0; + for (int i = 0; i < N; i++) + if (arr[i] == v) + count++; + + /* 출력 */ + printf("%d", count); + + /* 마무리 */ + free(arr); + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/10809.cpp b/baekjoon/Src/Baekjoon/Solved/10809.cpp new file mode 100644 index 0000000..a2f9a5e --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/10809.cpp @@ -0,0 +1,22 @@ +#include + +int main(void) { + char str[100] = {0}; + int numcount[26] = {0}; + + gets(str); + + for (int i = 0; i < 26; i++) + if (numcount[i] == 0) + numcount[i] = (-1); + + for (int i = 0; str[i] != '\0'; i++) { + if (numcount[str[i] - 97] == (-1)) + numcount[str[i] - 97] = i; + } + + for (int i = 0; i < 26; i++) + printf("%d ", numcount[i]); + + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/10816[mapset].cpp b/baekjoon/Src/Baekjoon/Solved/10816[mapset].cpp new file mode 100644 index 0000000..6c0835a --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/10816[mapset].cpp @@ -0,0 +1,42 @@ +#include +#include +using namespace std; + +int main(int argc, char* argv[]) { + /* Faster */ + ios::sync_with_stdio(0); + cin.tie(0); + cout.tie(0); + + /* Init */ + unordered_map um; + + /* Input */ + int n; + cin >> n; + while (n--) { + int x; + cin >> x; + if (um.find(x) == um.end()) // + um.insert(make_pair(x, 1)); + else // ִ + um.find(x)->second++; + } + int m; + cin >> m; + while (m--) { + int x; + cin >> x; + if (um.find(x) == um.end()) // + cout << '0' << ' '; + else + cout << um.find(x)->second << ' '; + } + + /* Return */ + return 0; +} + +/* +https://program-rest-area.tistory.com/102 +*/ diff --git a/baekjoon/Src/Baekjoon/Solved/10818.cpp b/baekjoon/Src/Baekjoon/Solved/10818.cpp new file mode 100644 index 0000000..7afcdd4 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/10818.cpp @@ -0,0 +1,29 @@ +#pragma warning(disable : 4996) +#include +#include + +int main(int argc, char* argv[]) { + int N, max, min = 0; + + scanf("%d", &N); + int* arr = (int*)calloc(N, sizeof(int)); + + for (int i = 0; i < N; i++) + scanf("%d", &arr[i]); + + max = arr[0]; + for (int i = 1; i < N; i++) + if (max < arr[i]) + max = arr[i]; + + min = arr[0]; + for (int i = 1; i < N; i++) + if (min > arr[i]) + min = arr[i]; + + printf("%d %d", min, max); + + free(arr); + + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/10828.cpp b/baekjoon/Src/Baekjoon/Solved/10828.cpp new file mode 100644 index 0000000..a83e753 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/10828.cpp @@ -0,0 +1,31 @@ +#pragma warning(disable : 4996) +#include +#include + +int main(int argc, char* argv[]) { + int n = 0; + char buf[6] = {0}; + + int idx = 0; + int arr[10000] = {0}; + + scanf("%d", &n); + + for (int i = 0; i < n; i++) { + scanf("%s", buf); + + if (strcmp(buf, "push") == 0) + scanf("%d\n", &arr[idx++]); + else if (strcmp(buf, "pop") == 0) + printf("%d\n", idx == 0 ? -1 : arr[(idx--) - 1]); + else if (strcmp(buf, "size") == 0) + printf("%d\n", idx); + else if (strcmp(buf, "empty") == 0) + printf("%d\n", idx == 0 ? 1 : 0); + else if (strcmp(buf, "top") == 0) { + printf("%d\n", idx == 0 ? -1 : arr[idx - 1]); + } + } + + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/10845.cpp b/baekjoon/Src/Baekjoon/Solved/10845.cpp new file mode 100644 index 0000000..26c6d82 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/10845.cpp @@ -0,0 +1,92 @@ +#include +#include +using namespace std; + +class queue { + private: + int* arr; + + int F; + int R; + + const int max = 10001; + + public: + /* Constructor & Destructor */ + queue() : F(0), R(0) { + arr = new int[max](); + } + ~queue() { + delete[] arr; + } + /* Method */ + void push(int elem) { + arr[++R] = elem; + } + int pop(void) { + if (F == R) + return -1; + else + return arr[++F]; + } + int size(void) { + return R - F; + } + int empty(void) { + if (F == R) + return 1; + else + return 0; + } + int front(void) { + if (F == R) + return -1; + else + return arr[F + 1]; + } + int back(void) { + if (F == R) + return -1; + else + return arr[R]; + } +}; + +int main(int argc, char* argv[]) { + /* Faster */ + ios::sync_with_stdio(0); + cin.tie(0); + cout.tie(0); + + /* Init */ + queue q; + + /* Input */ + int N; + cin >> N; + for (int i = 0; i < N; i++) { + string str; + cin >> str; + + if (str == "push") { + int elem; + cin >> elem; + q.push(elem); + } else if (str == "pop") { + cout << q.pop() << '\n'; + } else if (str == "size") { + cout << q.size() << '\n'; + } else if (str == "empty") { + cout << q.empty() << '\n'; + } else if (str == "front") { + cout << q.front() << '\n'; + } else if (str == "back") { + cout << q.back() << '\n'; + } + } + + /* End */ + return 0; +} + +/* 원형 큐 이용 안함 */ diff --git a/baekjoon/Src/Baekjoon/Solved/1085.cpp b/baekjoon/Src/Baekjoon/Solved/1085.cpp new file mode 100644 index 0000000..48e9a3e --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/1085.cpp @@ -0,0 +1,15 @@ +#pragma warning(disable : 4996) +#include + +int min(int a, int b) { + return a > b ? b : a; +} + +int main(int argc, char* argv[]) { + int x, y, w, h; + scanf("%d %d %d %d", &x, &y, &w, &h); + + printf("%d", min(min(w - x, x), min(h - y, y))); + + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/10866.cpp b/baekjoon/Src/Baekjoon/Solved/10866.cpp new file mode 100644 index 0000000..48e44a2 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/10866.cpp @@ -0,0 +1,69 @@ +#include +#include +#include +using namespace std; + +int main(int argc, char* argv[]) { + /* Faster */ + ios::sync_with_stdio(0); + cin.tie(0); + cout.tie(0); + + /* Init */ + deque dq; + + /* Input */ + int n; + cin >> n; + while (n--) { + string str; + cin >> str; + + if (str == "push_front") { + int x; + cin >> x; + dq.push_front(x); + } else if (str == "push_back") { + int x; + cin >> x; + dq.push_back(x); + } else if (str == "pop_front") { + if (dq.empty()) { + cout << "-1" << '\n'; + continue; + } + + cout << dq.front() << '\n'; + dq.pop_front(); + } else if (str == "pop_back") { + if (dq.empty()) { + cout << "-1" << '\n'; + continue; + } + + cout << dq.back() << '\n'; + dq.pop_back(); + } else if (str == "size") { + cout << dq.size() << '\n'; + } else if (str == "empty") { + cout << dq.empty() << '\n'; + } else if (str == "front") { + if (dq.empty()) { + cout << "-1" << '\n'; + continue; + } + + cout << dq.front() << '\n'; + } else if (str == "back") { + if (dq.empty()) { + cout << "-1" << '\n'; + continue; + } + + cout << dq.back() << '\n'; + } + } + + /* Return */ + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/10869.cpp b/baekjoon/Src/Baekjoon/Solved/10869.cpp new file mode 100644 index 0000000..cc2dc29 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/10869.cpp @@ -0,0 +1,18 @@ +#include +using std::cin; +using std::cout; +using std::endl; + +int main(void) { + int A; + int B; + + cin >> A >> B; + + cout << A + B << endl + << A - B << endl + << A * B << endl + << A / B << endl + << A % B << endl; + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/10870.cpp b/baekjoon/Src/Baekjoon/Solved/10870.cpp new file mode 100644 index 0000000..d67b09b --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/10870.cpp @@ -0,0 +1,18 @@ +#pragma warning(disable : 4996) +#include + +int fibo(int n) { + if (n <= 1) + return n; + else + return (fibo(n - 2) + fibo(n - 1)); +} + +int main(int argc, char* argv[]) { + int n; + scanf("%d", &n); + + printf("%d", fibo(n)); + + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/10871.cpp b/baekjoon/Src/Baekjoon/Solved/10871.cpp new file mode 100644 index 0000000..3a5ad23 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/10871.cpp @@ -0,0 +1,17 @@ +#pragma warning(disable : 4996) +#include +#include + +int main(void) { + int n, x; + scanf("%d %d", &n, &x); + + int* arr = (int*)calloc(n, sizeof(int)); + for (int i = 0; i < n; i++) scanf("%d", &arr[i]); + + for (int i = 0; i < n; i++) { + if (arr[i] < x) printf("%d ", arr[i]); + } + + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/10872.cpp b/baekjoon/Src/Baekjoon/Solved/10872.cpp new file mode 100644 index 0000000..4b6cb0a --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/10872.cpp @@ -0,0 +1,18 @@ +#pragma warning(disable : 4996) +#include + +int factorial(int n) { + if (n <= 1) + return 1; + else + return n * factorial(n - 1); +} + +int main(int argc, char* argv[]) { + int n; + scanf("%d", &n); + + printf("%d", factorial(n)); + + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/10926.cpp b/baekjoon/Src/Baekjoon/Solved/10926.cpp new file mode 100644 index 0000000..6bbb58e --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/10926.cpp @@ -0,0 +1,14 @@ +#include + +using std::cin; +using std::cout; +using std::endl; + +int main(void) { + char ID[51]; + + cin >> ID; + + cout << ID << "\?\?!" << endl; + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/10950.cpp b/baekjoon/Src/Baekjoon/Solved/10950.cpp new file mode 100644 index 0000000..80cc794 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/10950.cpp @@ -0,0 +1,16 @@ +#pragma warning(disable : 4996) +#include + +int main(int argc, char* argv[]) { + int T; + int A[100], B[100]; + scanf("%d", &T); + + for (int i = 0; i < T; i++) + scanf("%d %d", &A[i], &B[i]); + + for (int i = 0; i < T; i++) + printf("%d\n", A[i] + B[i]); + + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/10951.cpp b/baekjoon/Src/Baekjoon/Solved/10951.cpp new file mode 100644 index 0000000..628cd7a --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/10951.cpp @@ -0,0 +1,14 @@ +#pragma warning(disable : 4996) +#include + +int main(int argc, char* argv[]) { + int ch1, ch2; + while (true) { + scanf("%d %d", &ch1, &ch2); + if (feof(stdin) != 0) + break; + printf("%d\n", ch1 + ch2); + } + + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/10952.cpp b/baekjoon/Src/Baekjoon/Solved/10952.cpp new file mode 100644 index 0000000..e4835b9 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/10952.cpp @@ -0,0 +1,17 @@ +#pragma warning(disable : 4996) +#include +#include + +int main(void) { + int a, b = 0; + + while (true) { + scanf("%d %d", &a, &b); + if (a == 0 && b == 0) + break; + else + printf("%d\n", a + b); + } + + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/10989.cpp b/baekjoon/Src/Baekjoon/Solved/10989.cpp new file mode 100644 index 0000000..c72cdf2 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/10989.cpp @@ -0,0 +1,60 @@ +/*Counting Sort */ +#pragma warning(disable : 4996) +#include +#include +#include + +void counting_sort(int A[], int k, int n) { // k Է 迭 ִ. + /*1ܰ*/ + int* count = (int*)calloc(k + 1, sizeof(int)); + + for (int i = 0; i < n; i++) count[A[i]]++; + + // for (int i = 0; i < k + 1; i++)//Test + // printf("%d ", count[i]); + // printf("\n"); + + for (int i = 1; i < k + 1; i++) count[i] += count[i - 1]; + + // for (int i = 0; i < k + 1; i++)//Test + // printf("%d ", count[i]); + // printf("\n"); + + /*2ܰ*/ + int* Atmp = (int*)calloc(n, sizeof(int)); + + for (int i = 0; i < n; i++) Atmp[(count[A[i]]--) - 1] = A[i]; + + // for (int i = 0; i < n; i++)//Test + // printf("%d ", Atmp[i]); + + memcpy(A, Atmp, sizeof(int) * n); + + free(Atmp); + free(count); +} // ̰ Ⱦ. + +int main(void) { + int k = 10000; + int n; + scanf("%d", &n); + + int tmp = 0; + int* count = (int*)calloc(k + 1, sizeof(int)); + + for (int i = 0; i < n; i++) { + scanf("%d", &tmp); + count[tmp]++; + } + + // for (int i = 0; i < k + 1; i++)//Test + // printf("%d ", count[i]); + // printf("\n"); + + for (int i = 0; i < k + 1; i++) { + for (int j = 0; j < count[i]; j++) printf("%d\n", i); + } + + free(count); + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/10996.cpp b/baekjoon/Src/Baekjoon/Solved/10996.cpp new file mode 100644 index 0000000..b720d4d --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/10996.cpp @@ -0,0 +1,19 @@ +#pragma warning(disable : 4996) +#include + +int main(int argc, char* argv[]) { + int N; + scanf("%d", &N); + + for (int i = 0; i < N * 2; i++) { + for (int j = 0; j < N; j++) { + if ((i + j) % 2 == 0) // 짝수 + 짝수 = 홀수 + 홀수 = 짝수 + printf("*"); + else if ((i + j) % 2 == 1) // 홀수 + 짝수 = 홀수 + printf(" "); + } + printf("\n"); + } + + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/10998.cpp b/baekjoon/Src/Baekjoon/Solved/10998.cpp new file mode 100644 index 0000000..1681495 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/10998.cpp @@ -0,0 +1,10 @@ +#include + +int main(void) { + int A, B, result = 0; + + scanf("%d %d", &A, &B); + + printf("%d", A * B); + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/11003.cpp b/baekjoon/Src/Baekjoon/Solved/11003.cpp new file mode 100644 index 0000000..98ea8a1 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/11003.cpp @@ -0,0 +1,61 @@ +#include +#include +#include +using namespace std; + +struct cmp { // priority_queue를 위한 비교 함수. + bool operator()(const pair& a, const pair& b) { + if (a.second != b.second) + return a.second > b.second; // val 기준 내림차순 정렬. + else + return a.first > b.first; // idx 기준 내림차순 정렬. + } +}; + +int main(int argc, char* argv[]) { + /* Faster */ + ios::sync_with_stdio(0); + cin.tie(0); + cout.tie(0); + + /* Init */ + priority_queue, vector>, cmp> pq; // idx, val + + /* Input */ + int n, l; + cin >> n >> l; + for (int idx = 0; idx < n; idx++) { + /* Input */ + int val; + cin >> val; + + /* Logic */ + pq.push(make_pair(idx, val)); + + while (pq.top().first <= idx - l) + pq.pop(); + + /* Output */ + cout << pq.top().second << ' '; + } + + /* Return */ + return 0; +} + +/* +Sliding Window 알고리즘 + +Set 이용 + +[naive 풀이] +컨테이너 삽입 : O(1) +최솟값 찾기 : O(n) +컨테이너 삭제 : O(1) + +[priority_queue 이용 풀이] +컨테이너 삽입 : O(logn) +최솟값 찾기 : O(1) +컨테이너 삭제 : O(logn) + +*/ diff --git a/baekjoon/Src/Baekjoon/Solved/11021.cpp b/baekjoon/Src/Baekjoon/Solved/11021.cpp new file mode 100644 index 0000000..f86a418 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/11021.cpp @@ -0,0 +1,16 @@ +#pragma warning(disable : 4996) +#include + +int main(int argc, char* argv[]) { + int num; + int a, b; + + scanf("%d", &num); + + for (int i = 0; i < num; i++) { + scanf("%d %d", &a, &b); + printf("Case #%d: %d\n", i + 1, a + b); + } + + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/11022.cpp b/baekjoon/Src/Baekjoon/Solved/11022.cpp new file mode 100644 index 0000000..b32586f --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/11022.cpp @@ -0,0 +1,16 @@ +#pragma warning(disable : 4996) +#include + +int main(int argc, char* argv[]) { + int num; + int a, b; + + scanf("%d", &num); + + for (int i = 0; i < num; i++) { + scanf("%d %d", &a, &b); + printf("Case #%d: %d + %d = %d\n", i + 1, a, b, a + b); + } + + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/11047.cpp b/baekjoon/Src/Baekjoon/Solved/11047.cpp new file mode 100644 index 0000000..aafb5b2 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/11047.cpp @@ -0,0 +1,33 @@ +#pragma warning(disable : 4996) +#include +#include + +int main(void) { + int count = 0; + + /* Input */ + int n, k; + scanf("%d %d", &n, &k); + + int* arr = (int*)calloc(n, sizeof(int)); + for (int i = n - 1; i >= 0; i--) scanf("%d", &arr[i]); + + ///* Test */ + // for (int i = 0; i < n; i++) + // printf("%d ", arr[i]); + // printf("\n"); + + /* Greedy */ + for (int i = 0; i < n; i++) { + while (k - arr[i] >= 0) { + k -= arr[i]; + count++; + // printf("arr[%d]=%d | k=%d | count=%d\n", i, arr[i], k, count); + } + } + + /* Output */ + printf("%d", count); + + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/11050 11051.cpp b/baekjoon/Src/Baekjoon/Solved/11050 11051.cpp new file mode 100644 index 0000000..0144a91 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/11050 11051.cpp @@ -0,0 +1,22 @@ +#pragma warning(disable : 4996) +#include + +long long memo[1001][1002]; + +long long bc(int n, int k) { // nCk ϱ. + if (k == 0 || k == n) + return 1; + else if (memo[n][k] != 0) + return memo[n][k]; + else + return memo[n][k] = (bc(n - 1, k - 1) + bc(n - 1, k)) % 10007; +} + +int main(void) { + int n, k; + scanf("%d %d", &n, &k); + + printf("%lld", bc(n, k) % 100); + + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/1106[DP]_BU.cpp b/baekjoon/Src/Baekjoon/Solved/1106[DP]_BU.cpp new file mode 100644 index 0000000..0b61e1c --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/1106[DP]_BU.cpp @@ -0,0 +1,45 @@ +#pragma warning(disable : 4996) +#include +#include +#include +using namespace std; + +int table[21][100001] = {}; + +int main(int argc, char* argv[]) { + /* Input */ + int C, N; + scanf("%d %d", &C, &N); + + pair p[21]; + for (int i = 1; i <= N; i++) { + int c, n; + scanf("%d %d", &c, &n); + p[i] = make_pair(c, n); + } + + /* DP */ + for (int i = 1; true; i++) { + /* DP */ + for (int j = 1; j <= N; j++) + table[j][i] = + max(table[j - 1][i], + i - p[j].first >= 0 ? table[j][i - p[j].first] + p[j].second : 0); + + /* Output */ + if (table[N][i] >= C) { + printf("%d", i); + break; + } + } + + /* End */ + return 0; +} + +/* +C(ִ 1000) +(ִ 100), (ּ 1) + +, table ũ ִ 100000 +*/ diff --git a/baekjoon/Src/Baekjoon/Solved/1110.cpp b/baekjoon/Src/Baekjoon/Solved/1110.cpp new file mode 100644 index 0000000..0e10728 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/1110.cpp @@ -0,0 +1,24 @@ +#pragma warning(disable : 4996) // visual studio scanf 오류 방지. +#include + +int cycle(int n) { + int original = n; + int count = 0; + + /* 식이 최소 1번은 실행되어야 하기에, do while 사용 */ + do { + n = ((n % 10) * 10) + (((n / 10) + (n % 10)) % 10); + count++; + } while (original != n); + + return count; +} + +int main(int argc, char* argv[]) { + int N; + scanf("%d", &N); + + printf("%d", cycle(N)); + + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/11279[DS].cpp b/baekjoon/Src/Baekjoon/Solved/11279[DS].cpp new file mode 100644 index 0000000..049dc34 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/11279[DS].cpp @@ -0,0 +1,39 @@ +#include +#include +using namespace std; + +int main(int argc, char* argv[]) { + /* Faster */ + ios::sync_with_stdio(0); + cin.tie(0); + cout.tie(0); + + /* Init */ + priority_queue, less> pq; + + /* Input */ + int n; + cin >> n; + for (int i = 0; i < n; i++) { + /* Input */ + int x; + cin >> x; + + /* Calculation */ + if (x == 0) { + if (pq.empty()) { + cout << 0 << '\n'; + } else { + cout << pq.top() << '\n'; + pq.pop(); + } + } else { + pq.push(x); + } + } + + /* Return */ + return 0; +} + +/* 1927, 11286 Ʈ */ diff --git a/baekjoon/Src/Baekjoon/Solved/11286[DS].cpp b/baekjoon/Src/Baekjoon/Solved/11286[DS].cpp new file mode 100644 index 0000000..924f79a --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/11286[DS].cpp @@ -0,0 +1,57 @@ +#include +#include +using namespace std; + +struct cmp { + bool operator()(const pair& a, const pair& b) { + // ٸٸ. + if (a.first != b.first) + return a.first > b.first; + // ٸ. + else + return a.second < b.second; + } +}; + +int main(int argc, char* argv[]) { + /* Faster */ + ios::sync_with_stdio(0); + cin.tie(0); + cout.tie(0); + + /* Init */ + priority_queue, vector>, cmp> pq; + + /* Input */ + int n; + cin >> n; + for (int i = 0; i < n; i++) { + /* Input */ + int x; + cin >> x; + + /* Calculation */ + if (x == 0) { + if (pq.empty()) { + cout << 0 << '\n'; + } else { + if (pq.top().second == '+') + cout << pq.top().first << '\n'; + else + cout << -pq.top().first << '\n'; + + pq.pop(); + } + } else { + if (x >= 0) + pq.push(make_pair(x, '+')); + else + pq.push(make_pair(-x, '-')); + } + } + + /* Return */ + return 0; +} + +/* 1927, 11279 Ʈ */ diff --git a/baekjoon/Src/Baekjoon/Solved/11382.cpp b/baekjoon/Src/Baekjoon/Solved/11382.cpp new file mode 100644 index 0000000..df5d898 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/11382.cpp @@ -0,0 +1,21 @@ +#include +using namespace std; + +int main(int argc, char* argv[]) { + /* Faster */ + ios::sync_with_stdio(0); + cin.tie(0); + cout.tie(0); + + /* Input */ + long a, b, c; + cin >> a >> b >> c; + + /* Output */ + cout << a + b + c; + + /* Return */ + return 0; +} + +/* 10의 12승 = 약 2의 40승. 따라서, int로 표현할 수 있는 범위를 넘어선다. */ diff --git a/baekjoon/Src/Baekjoon/Solved/1149.cpp b/baekjoon/Src/Baekjoon/Solved/1149.cpp new file mode 100644 index 0000000..4f21066 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/1149.cpp @@ -0,0 +1,32 @@ +#pragma warning(disable : 4996) +#include + +#define min(a, b) (((a) < (b)) ? (a) : (b)) + +int table[1001][3] = {}; // R=0, G=1, B=2 + +int main(int argc, char* argv[]) { + /* Input */ + int N; + scanf("%d", &N); + for (int i = 1; i <= N; i++) + scanf("%d %d %d", &table[i][0], &table[i][1], &table[i][2]); + + /* DP */ + for (int i = 2; i <= N; i++) { + table[i][0] += min(table[i - 1][1], table[i - 1][2]); + table[i][1] += min(table[i - 1][0], table[i - 1][2]); + table[i][2] += min(table[i - 1][0], table[i - 1][1]); + } + + /* Output */ + printf("%d", min(table[N][0], min(table[N][1], table[N][2]))); + + /* End */ + return 0; +} + +/* +Bottom Up 방식으로 풀었다. +Top Down 방식으로도 풀 수 있을지 고민해보자. +*/ diff --git a/baekjoon/Src/Baekjoon/Solved/1152.cpp b/baekjoon/Src/Baekjoon/Solved/1152.cpp new file mode 100644 index 0000000..0c24fe5 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/1152.cpp @@ -0,0 +1,49 @@ +#include +#include +#include +#include +#define MAX_LEN 1000000 + +char* trim(char* str) { + char* end; + + while (isspace((unsigned char)*str)) str++; + + if (*str == 0) return str; + + end = str + strlen(str) - 1; + while (end > str && isspace((unsigned char)*end)) end--; + + end[1] = '\0'; + + return str; +} + +int main(int argc, char* argv[]) { + int count = 0; + char* str = (char*)calloc(MAX_LEN, sizeof(char)); + + fgets(str, MAX_LEN, stdin); + // printf("%s", str); + + if (strlen(str) == 2) { // ϳ ԷµǾ if ó + // ־ 0 µǰ + if (str[0] == ' ') { + printf("0\n"); + return 0; + } + } + + char* tmp = trim(str); + + // printf("%s", tmp); + + for (int i = 0; i < MAX_LEN; i++) + if (tmp[i] == ' ') count++; + + printf("%d\n", count + 1); + + free(str); + + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/1157.cpp b/baekjoon/Src/Baekjoon/Solved/1157.cpp new file mode 100644 index 0000000..3509f6d --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/1157.cpp @@ -0,0 +1,41 @@ +#include + +void Capital_to_Small(char* str) { + for (int i = 0; str[i] != '\0'; i++) + if (str[i] >= 'A' && str[i] <= 'Z') + str[i] += 32; +} + +int main(void) { + char str[1000002] = {0}; + int Alphabet[26] = {0}; + int Max = 0, Count = 0, Maxvalue = 0; + + scanf("%s", str); + + Capital_to_Small(str); + + for (int i = 0; str[i] != '\0'; i++) + Alphabet[str[i] - 'a']++; + + Max = Alphabet[0]; + + for (int i = 0; i <= 24; i++) + if (Max < Alphabet[i + 1]) { + Max = Alphabet[i + 1]; + Maxvalue = (i + 1); + } + + for (int i = 0; i <= 25; i++) + if (Max == Alphabet[i]) + Count++; + // Count == 1 이면 해당하는 최대값 같는 알파벳 출력, Count>=2 이면 ? 출력 + + if (Count == 1) + printf("%c", Maxvalue + 65); + + else + printf("?"); + + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/1158.cpp b/baekjoon/Src/Baekjoon/Solved/1158.cpp new file mode 100644 index 0000000..33902ad --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/1158.cpp @@ -0,0 +1,38 @@ +#include +#include +using namespace std; + +int main(int argc, char* argv[]) { + /* Faster */ + ios::sync_with_stdio(0); + cin.tie(0); + cout.tie(0); + + /* Init */ + queue q; + + /* Input */ + int n, k; + cin >> n >> k; + for (int i = 0; i < n; i++) q.push(i + 1); + + /* Josephus */ + cout << '<'; + while (true) { + for (int i = 0; i < k - 1; i++) { + q.push(q.front()); + q.pop(); + } + + cout << q.front(); + q.pop(); + + if (q.empty()) break; + + cout << ", "; + } + cout << '>'; + + /* Return */ + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/11650.cpp b/baekjoon/Src/Baekjoon/Solved/11650.cpp new file mode 100644 index 0000000..fb221fc --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/11650.cpp @@ -0,0 +1,63 @@ +#pragma warning(disable : 4996) +#include +#include +#include + +typedef struct { + int x; + int y; +} coordinate; + +void merge(coordinate A[], int l, int m, int r) { + int i = l; + int j = m + 1; + int t = 0; + coordinate* tmp = (coordinate*)calloc(r - l + 1, sizeof(coordinate)); + + while (i <= m && j <= r) { + if (A[i].x != A[j].x) { // xǥ . + if (A[i].x < A[j].x) + tmp[t++] = A[i++]; + else if (A[i].x > A[j].x) + tmp[t++] = A[j++]; + } else { // xǥ . + if (A[i].y < A[j].y) + tmp[t++] = A[i++]; + else if (A[i].y > A[j].y) + tmp[t++] = A[j++]; + } + } + + while (i <= m) tmp[t++] = A[i++]; + while (j <= r) tmp[t++] = A[j++]; + + for (int k = l; k <= r; k++) A[k] = tmp[k - l]; + + free(tmp); +} + +void merge_sort(coordinate A[], int l, int r) { + if (l < r) { + int m = (l + r) / 2; + + merge_sort(A, l, m); + merge_sort(A, m + 1, r); + + merge(A, l, m, r); + } +} + +int main(void) { + int n = 0; + scanf("%d", &n); + + coordinate* A = (coordinate*)calloc(n, sizeof(coordinate)); + for (int i = 0; i < n; i++) scanf("%d %d", &A[i].x, &A[i].y); + + merge_sort(A, 0, n - 1); + + for (int i = 0; i < n; i++) printf("%d %d\n", A[i].x, A[i].y); + + free(A); + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/11651.cpp b/baekjoon/Src/Baekjoon/Solved/11651.cpp new file mode 100644 index 0000000..8c62a40 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/11651.cpp @@ -0,0 +1,63 @@ +#pragma warning(disable : 4996) +#include +#include +#include + +typedef struct { + int x; + int y; +} coordinate; + +void merge(coordinate A[], int l, int m, int r) { + int i = l; + int j = m + 1; + int t = 0; + coordinate* tmp = (coordinate*)calloc(r - l + 1, sizeof(coordinate)); + + while (i <= m && j <= r) { + if (A[i].y == A[j].y) { + if (A[i].x < A[j].x) + tmp[t++] = A[i++]; + else if (A[i].x > A[j].x) + tmp[t++] = A[j++]; + } else { + if (A[i].y < A[j].y) + tmp[t++] = A[i++]; + else if (A[i].y > A[j].y) + tmp[t++] = A[j++]; + } + } + + while (i <= m) tmp[t++] = A[i++]; + while (j <= r) tmp[t++] = A[j++]; + + for (int k = l; k <= r; k++) A[k] = tmp[k - l]; + + free(tmp); +} + +void merge_sort(coordinate A[], int l, int r) { + if (l < r) { + int m = (l + r) / 2; + + merge_sort(A, l, m); + merge_sort(A, m + 1, r); + + merge(A, l, m, r); + } +} + +int main(void) { + int n = 0; + scanf("%d", &n); + + coordinate* A = (coordinate*)calloc(n, sizeof(coordinate)); + for (int i = 0; i < n; i++) scanf("%d %d", &A[i].x, &A[i].y); + + merge_sort(A, 0, n - 1); + + for (int i = 0; i < n; i++) printf("%d %d\n", A[i].x, A[i].y); + + free(A); + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/11654.cpp b/baekjoon/Src/Baekjoon/Solved/11654.cpp new file mode 100644 index 0000000..ced30c8 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/11654.cpp @@ -0,0 +1,10 @@ +#include + +int main(void) { + char A; + + scanf("%c", &A); + + printf("%d", A); + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/11720.cpp b/baekjoon/Src/Baekjoon/Solved/11720.cpp new file mode 100644 index 0000000..eff2869 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/11720.cpp @@ -0,0 +1,16 @@ +#include + +int main(void) { + int N, sum = 0; + char num[1000] = {0}; + + scanf("%d", &N); + scanf("%s", num); + + for (int i = 0; i < N; i++) + sum += (num[i] - '0'); + + printf("%d", sum); + + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/11721.cpp b/baekjoon/Src/Baekjoon/Solved/11721.cpp new file mode 100644 index 0000000..0cd8a6c --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/11721.cpp @@ -0,0 +1,18 @@ +#include + +int main(void) { + char str[100] = {0}; + int count = 0; + + gets(str); + + for (int i = 0; str[i] != '\0'; i++) { + printf("%c", str[i]); + count++; + if (count == 10) { + printf("\n"); + count = 0; + } + } + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/11723[bitmask].cpp b/baekjoon/Src/Baekjoon/Solved/11723[bitmask].cpp new file mode 100644 index 0000000..ab05265 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/11723[bitmask].cpp @@ -0,0 +1,99 @@ +#include +#include +using namespace std; + +class set { + private: + int s; + + public: + /* Constructor & Destructor */ + set() : s(0) {} + ~set() {} + /* Method */ + void add(int x) { + s = s | (1 << x); + } + void remove(int x) { + s = s & ~(1 << x); + } + bool check(int x) { + return (s & (1 << x)) != 0; + } + void toggle(int x) { + s = s ^ (1 << x); + } + void all(void) { + s = 0b00000000'00011111'11111111'11111110; + } + void empty(void) { + s = 0b00000000'00000000'00000000'00000000; + } + /* Debug */ + // int gets(void) { + // return s; + // } +}; + +int main(int argc, char* argv[]) { + /* Faster */ + ios::sync_with_stdio(0); + cin.tie(0); + cout.tie(0); + + /* Init */ + set s; + + /* Input */ + int m; + cin >> m; + while (m--) { + /* Input */ + string str; + cin >> str; + + /* Add */ + if (str == "add") { + int x; + cin >> x; + s.add(x); + } + /* Remove */ + else if (str == "remove") { + int x; + cin >> x; + s.remove(x); + } + /* Check */ + else if (str == "check") { + int x; + cin >> x; + cout << s.check(x) << '\n'; + } + /* Toggle */ + else if (str == "toggle") { + int x; + cin >> x; + s.toggle(x); + } + /* All */ + else if (str == "all") { + s.all(); + } + /* Empty */ + else if (str == "empty") { + s.empty(); + } + + /* Debug */ + // cout << "s : " << s.gets() << '\n'; + } + + /* Return */ + return 0; +} + +/* +https://travelbeeee.tistory.com/451 +https://www.acmicpc.net/source/60817704 +*/ diff --git a/baekjoon/Src/Baekjoon/Solved/11866[DS].cpp b/baekjoon/Src/Baekjoon/Solved/11866[DS].cpp new file mode 100644 index 0000000..4db16cf --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/11866[DS].cpp @@ -0,0 +1,46 @@ +#include +#include +using namespace std; + +int main(int argc, char* argv[]) { + /* Faster */ + ios::sync_with_stdio(0); + cin.tie(0); + cout.tie(0); + + /* Init */ + queue q; + + /* Input */ + int n, k; + cin >> n >> k; + for (int i = 0; i < n; i++) + q.push(i + 1); + + /* Josephus */ + cout << '<'; + + while (true) { + for (int i = 0; i < k - 1; i++) { + q.push(q.front()); + q.pop(); + } + + cout << q.front(); + + q.pop(); + + if (q.empty()) + break; + + cout << ", "; + } + cout << '>'; + + /* Return */ + return 0; +} + +/* +似Ǫ Ʈ . +*/ diff --git a/baekjoon/Src/Baekjoon/Solved/1197.cpp b/baekjoon/Src/Baekjoon/Solved/1197.cpp new file mode 100644 index 0000000..c33131d --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/1197.cpp @@ -0,0 +1,85 @@ +#pragma warning(disable : 4996) +#include +#include +#include + +/* Struct */ +typedef struct { + int p; + int rank; +} NODE; + +typedef struct { + int u; + int v; + int weight; +} EDGE; + +/* Function */ +/* Disjoint Set*/ +void DS_make(NODE* node, int u) { + node[u].p = u; + node[u].rank = 0; +} + +int DS_find(NODE* node, int u) { + if (node[u].p != u) node[u].p = DS_find(node, node[u].p); + return node[u].p; +} + +bool DS_merge(NODE* node, int u, int v) { + int ur = DS_find(node, u); + int vr = DS_find(node, v); + if (ur == vr) return false; + if (node[ur].rank > node[vr].rank) + node[vr].p = ur; + else { + node[ur].p = vr; + if (node[ur].rank == node[vr].rank) node[vr].rank += 1; + } + return true; +} + +int compare(const EDGE& a, const EDGE& b) { return a.weight < b.weight; } + +int main(void) { + /* Input */ + int v, e; + scanf("%d %d", &v, &e); + + EDGE* edge = (EDGE*)calloc(e, sizeof(EDGE)); + for (int i = 0; i < e; i++) + scanf("%d %d %d", &edge[i].u, &edge[i].v, &edge[i].weight); + + NODE* node = (NODE*)calloc(v + 1, sizeof(NODE)); + + ///* Test */ + // printf("\n"); + // for (int i = 0; i < e; i++) + // printf("%d %d %d\n", edge[i].u, edge[i].v, edge[i].weight); + + /* Make Set */ + for (int i = 0; i < v; i++) DS_make(node, i); + + /* Order */ + std::sort(edge, edge + e, compare); + + ///* Test */ + // printf("\n"); + // for (int i = 0; i < e; i++) + // printf("%d %d %d\n", edge[i].u, edge[i].v, edge[i].weight); + + /* Kruscal */ + int w = 0; + for (int i = 0; i < e; i++) { + if (DS_find(node, edge[i].u) != DS_find(node, edge[i].v)) { + w += edge[i].weight; + DS_merge(node, edge[i].u, edge[i].v); + } + } + + /* Output */ + printf("%d", w); + + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/1213[GR].cpp b/baekjoon/Src/Baekjoon/Solved/1213[GR].cpp new file mode 100644 index 0000000..010f8a7 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/1213[GR].cpp @@ -0,0 +1,42 @@ +#pragma warning(disable : 4996) +#include +#include +using namespace std; + +int main(int argc, char* argv[]) { + /* Init */ + int AZalp[26] = {}; // A~Z ĺ 迭. + char str[51]; + scanf("%s", str); //'\0'. + + /* */ + for (int i = 0; str[i] != '\0'; i++) AZalp[str[i] - 65]++; + + /* Ȧ ľ */ + int oddnum = 0; + for (int i = 0; i < 26; i++) + if (AZalp[i] % 2 == 1) + if (++oddnum >= 2) { + printf("I'm Sorry Hansoo"); + return 0; + } + + /* ġ */ + int str_idx = 0; + // + for (int AZalp_idx = 0; AZalp_idx < 26; AZalp_idx++) + while (AZalp[AZalp_idx] >= 2) { + str[str_idx] = str[strlen(str) - str_idx - 1] = AZalp_idx + 65; + AZalp[AZalp_idx] -= 2; + str_idx++; + } + // + for (int AZalp_idx = 0; AZalp_idx < 26; AZalp_idx++) + if (AZalp[AZalp_idx] == 1) str[str_idx] = AZalp_idx + 65; + + /* Output */ + printf("%s", str); + + /* End */ + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/1259.cpp b/baekjoon/Src/Baekjoon/Solved/1259.cpp new file mode 100644 index 0000000..0d9c23d --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/1259.cpp @@ -0,0 +1,36 @@ +#pragma warning(disable : 4996) +#include +#include +#include + +int main(int argc, char* argv[]) { + /* 선언 */ + char palin[7]; // '\0', '\n' 포함. + + while (true) { + /* 팰린드롬 여부 판단 변수 선언 */ + bool ispalin = true; + + /* 문자열 입력 받은 후, 개행문자 제거 */ + fgets(palin, sizeof(palin), stdin); + if (palin[strlen(palin) - 1] == '\n') + palin[strlen(palin) - 1] = '\0'; + + /* 0값이 입력된 경우, 종료 */ + if (strlen(palin) == 1 && palin[0] == '0') + break; + + /* 팰린드롬 여부 판단 */ + for (int i = 0; i < strlen(palin); i++) + if (palin[i] != palin[strlen(palin) - 1 - i]) + ispalin = false; + + /* 출력 */ + if (ispalin == false) + printf("no\n"); + else if (ispalin == true) + printf("yes\n"); + } + + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/1260[Graph].cpp b/baekjoon/Src/Baekjoon/Solved/1260[Graph].cpp new file mode 100644 index 0000000..d3dccef --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/1260[Graph].cpp @@ -0,0 +1,84 @@ +#include +#include +#include +#include +#include +using namespace std; + +int main(int argc, char* argv[]) { + /* Faster */ + ios::sync_with_stdio(0); + cin.tie(0); + cout.tie(0); + + /* Init */ + vector> vertex; // dfs, bfs + vector> edge; + stack s; + queue q; + + /* Input */ + int n, m, v; + cin >> n >> m >> v; + + vertex.resize(n + 1, pair(false, false)); + edge.resize(n + 1); + + for (int i = 0; i < m; i++) { + int n1, n2; + cin >> n1 >> n2; + + edge[n1].push_back(n2); + edge[n2].push_back(n1); + } + + /* DFS */ + // + for (int i = 1; i < edge.size(); i++) sort(edge[i].rbegin(), edge[i].rend()); + + // DFS + s.push(v); + while (!s.empty()) { + int top = s.top(); + s.pop(); + + if (vertex[top].first) continue; + + vertex[top].first = true; + cout << top << ' '; + + for (auto i : edge[top]) + if (!vertex[i].first) s.push(i); + } + + cout << '\n'; + + /* BFS */ + // + for (int i = 1; i < edge.size(); i++) sort(edge[i].begin(), edge[i].end()); + + // BFS + q.push(v); + while (!q.empty()) { + int top = q.front(); + q.pop(); + + if (vertex[top].second) continue; + + vertex[top].second = true; + cout << top << ' '; + + for (auto i : edge[top]) + if (!vertex[i].second) q.push(i); + } + + /* Return */ + return 0; +} + +/* Debug : Edge */ +// for (auto i : edge) { +// for (auto j : i) +// cout << j << ' '; +// cout << '\n'; +// } diff --git a/baekjoon/Src/Baekjoon/Solved/12865[DP]_BU.cpp b/baekjoon/Src/Baekjoon/Solved/12865[DP]_BU.cpp new file mode 100644 index 0000000..7a6268f --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/12865[DP]_BU.cpp @@ -0,0 +1,70 @@ +#pragma warning(disable : 4996) +#include +#define max(a, b) (((a) > (b)) ? (a) : (b)) +using namespace std; + +typedef struct { + int W; + int V; +} Item; + +int table[101][100001] = {}; +Item item[101] = {}; + +int main(int argc, char* argv[]) { + /* Input */ + int N, K; + scanf("%d %d", &N, &K); + for (int i = 1; i <= N; i++) + scanf("%d %d", &item[i].W, &item[i].V); + + /* DP */ + for (int col = 1; col <= N; col++) + for (int row = 1; row <= K; row++) + table[col][row] = max( + table[col - 1][row], + row - item[col].W >= 0 ? table[col - 1][row - item[col].W] + item[col].V : 0); + + ///* Debug */ + // for (int col = 0; col <= N; col++) { + // for (int row = 0; row <= K; row++) { + // printf("%3d", table[col][row]); + // } + // printf("\n"); + // } + + /* Output */ + printf("%d", table[N][K]); + + /* End */ + return 0; +} + +/* simple version */ +#pragma warning(disable : 4996) +#include +#include +using namespace std; + +int table[100001] = {}; + +int main(int argc, char* argv[]) { + /* Input & DP */ + int N, K; + scanf("%d %d", &N, &K); + + for (int i = 1; i <= N; i++) { + int W, V; + scanf("%d %d", &W, &V); + + for (int j = K; j >= W; j--) + table[j] = max(table[j], table[j - W] + V); + } + + /* Output */ + printf("%d", table[K]); + + /* End */ + return 0; +} +/* 12920 Ʈ */ diff --git a/baekjoon/Src/Baekjoon/Solved/12920[DP]_BU.cpp b/baekjoon/Src/Baekjoon/Solved/12920[DP]_BU.cpp new file mode 100644 index 0000000..d79aed7 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/12920[DP]_BU.cpp @@ -0,0 +1,142 @@ +/* Ǯ */ +#pragma warning(disable : 4996) +#include +#include +using namespace std; + +int table[10001] = {}; + +int main(int argc, char* argv[]) { + /* Input & DP */ + int N, M; + scanf("%d %d", &N, &M); + + for (int i = 0; i < N; i++) { + int V, C, K; + scanf("%d %d %d", &V, &C, &K); + + for (int j = 1; K > 0; j <<= 1) { + int mul = min(j, K); + K -= mul; + + for (int l = M; l >= V * mul; l--) + table[l] = max(table[l], table[l - V * mul] + C * mul); + } + } + + /* Output */ + printf("%d", table[M]); + + /* End */ + return 0; +} +/* ð ʰ Ǯ */ +#pragma warning(disable : 4996) +#include +#include +#include +#include +using namespace std; + +int table[10001] = {}; + +int main(int argc, char* argv[]) { + /* Input & DP */ + int N, M; + scanf("%d %d", &N, &M); + + for (int i = 0; i < N; i++) { + int V, C, K; + scanf("%d %d %d", &V, &C, &K); + + for (int j = M; j >= V; j--) { + vector tmp(K + 1); + + for (int l = 0; l <= K; l++) + if (j - (K - l) * V >= 0) + tmp[l] = table[j - (K - l) * V] + C * (K - l); + + table[j] = *max_element(tmp.begin(), tmp.end()); + } + + ///* Debug */ + // for (int i = 0; i <= M; i++) + // printf("%3d", table[i]); + // printf("\n"); + } + + /* Output */ + printf("%d", table[M]); + + /* End */ + return 0; +} +/* ð ʰ Ǯ */ +#pragma warning(disable : 4996) +#include + +using namespace std; + +int table[10001] = {}; + +int main(int argc, char* argv[]) { + /* Input & DP */ + int N, M; + scanf("%d %d", &N, &M); + + for (int i = 0; i < N; i++) { + int V, C, K; + scanf("%d %d %d", &V, &C, &K); + + for (int j = M; j >= V; j--) { + for (int l = 0; l <= K; l++) + if (j - (K - l) * V >= 0 && table[j] < table[j - (K - l) * V] + C * (K - l)) + table[j] = table[j - (K - l) * V] + C * (K - l); + } + + ///* Debug */ + // for (int i = 0; i <= M; i++) + // printf("%3d", table[i]); + // printf("\n"); + } + + /* Output */ + printf("%d", table[M]); + + /* End */ + return 0; +} +/* ð ʰ Ǯ */ +#pragma warning(disable : 4996) +#include +#include +using namespace std; + +int table[10001] = {}; + +int main(int argc, char* argv[]) { + /* Input & DP */ + int N, M; + scanf("%d %d", &N, &M); + + for (int i = 0; i < N; i++) { + int V, C, K; + scanf("%d %d %d", &V, &C, &K); + + for (int j = 0; j < K; j++) + for (int k = M; k >= V; k--) + table[k] = max(table[k], table[k - V] + C); + } + + /* Output */ + printf("%d", table[M]); + + /* End */ + return 0; +} + +/* +Ʈŷ +Ʈڿ +12865 Ʈ +*/ diff --git a/baekjoon/Src/Baekjoon/Solved/1316.cpp b/baekjoon/Src/Baekjoon/Solved/1316.cpp new file mode 100644 index 0000000..a199ee8 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/1316.cpp @@ -0,0 +1,34 @@ +#include + +int main(void) { + int Wordnum, Answer = 0; + char Word[100] = {0}; + int Alphabet[26] = {0}; + + scanf("%d", &Wordnum); + + for (int i = 0; i < Wordnum; i++) // Wordnum 만큼 반복 + { + scanf("%s", Word); + + // 그룹단어 판단 START + + for (int j = 0; Word[j] != '\0'; j++) + if (Word[j] != Word[j + 1]) + Alphabet[Word[j] - 'a']++; + + for (int j = 0; j < 26; j++) { + if (Alphabet[j] >= 2) + break; + if (j == 25) + Answer++; + } + + for (int j = 0; j < 26; j++) + Alphabet[j] = 0; + + // 그룹단어 판단 FINISH + } + printf("%d", Answer); + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/1330.cpp b/baekjoon/Src/Baekjoon/Solved/1330.cpp new file mode 100644 index 0000000..11ac4e8 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/1330.cpp @@ -0,0 +1,17 @@ +#include + +int main(int argc, char *argv[]) { + int A, B = 0; + scanf("%d %d", &A, &B); + + if (A > B) + printf(">"); + + else if (A < B) + printf("<"); + + else if (A == B) + printf("=="); + + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/13305[GR].cpp b/baekjoon/Src/Baekjoon/Solved/13305[GR].cpp new file mode 100644 index 0000000..65e2512 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/13305[GR].cpp @@ -0,0 +1,95 @@ +#pragma warning(disable : 4996) +#include +#include +#include +using namespace std; + +typedef long long LL; + +int min_idx(LL arr[], int e_idx) { // idx '0' 'e_idx' ߿ min_idx ã. + int minimum = INT_MAX; + int idx = 0; + + for (int i = 0; i <= e_idx; i++) + if (arr[i] < minimum) { + minimum = arr[i]; + idx = i; + } + + return idx; +} + +/* + ̿, ־ ( ϶) +O(n^2) ð ҿȴ. (quick sort ־ ) +calculate_long ̿ϸ 58 ´. +*/ +LL calculate_long(LL dist[], LL cost[], int e_idx) { // e_idx = end index + /* Exit */ + if (e_idx == 0) return 0; + + /* Init */ + LL ans = 0; // 䰪. + int pivot = min_idx(cost, e_idx - 1); // ð⵵ O(n) + + /* Calculate */ + for (int i = pivot; i < e_idx; i++) + ans += cost[pivot] * dist[i]; + + /* Divide and Conquer */ + return calculate_long(dist, cost, pivot) + ans; +} + +/* O(n) ð⵵ */ +LL calculate_short(LL dist[], LL cost[], int e_idx) { + /* Init */ + LL ans = 0; + + /* Calculate */ + for (int i = 0, cost_now = cost[0]; i < e_idx; i++) { + ans += cost_now * dist[i]; + + if (cost_now > cost[i + 1]) + cost_now = cost[i + 1]; + } + + return ans; +} + +int main(int argc, char* argv[]) { + /* Input */ + int N; + scanf("%d", &N); + + LL* dist = new LL[N]; + for (int i = 0; i < N - 1; i++) + scanf("%lld", &dist[i]); + + LL* cost = new LL[N]; + for (int i = 0; i < N; i++) + scanf("%lld", &cost[i]); + + /* Output */ + // printf("%lld", calculate_long(dist, pric, N - 1)); //O(n^2)Ǯ + printf("%lld", calculate_short(dist, cost, N - 1)); + + /* End */ + delete[] dist; + delete[] cost; + return 0; +} + +/* +, ϸũ . + +C++ Ÿ Ҵ ̿. + Ǯ. + +[ٹ] +⸧ 󿡼 ⸧ ־ Ѵ. + + 2 󿡼 ⸧ ־ Ѵ. + +[ans ] +10^9 = 10 , 10^9 * 10^9 = 10^18, 10^18 = 10 +*/ diff --git a/baekjoon/Src/Baekjoon/Solved/1339[GR].cpp b/baekjoon/Src/Baekjoon/Solved/1339[GR].cpp new file mode 100644 index 0000000..b7fb999 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/1339[GR].cpp @@ -0,0 +1,41 @@ +#pragma warning(disable : 4996) +#include +#include +#include +#include +using namespace std; + +int compare(const void *a, const void *b) { return *(int *)b - *(int *)a; } + +int main(int argc, char *argv[]) { + /* Init */ + int AZweight[26] = {}; // A~Z شϴ ġ . + + /* Input & Weight Calculation */ + int N; + scanf("%d", &N); + for (int i = 0; i < N; i++) { + char word[9]; + scanf("%s", word); + + for (int i = 0; i < strlen(word); i++) + AZweight[word[i] - 65] += pow(10, strlen(word) - i - 1); + } + + /* Sort */ + qsort(AZweight, sizeof(AZweight) / sizeof(int), sizeof(int), compare); + + /* Output */ + int sum = 0, num = 9; + for (int i = 0; AZweight[i] != 0; i++) sum += AZweight[i] * num--; + + printf("%d", sum); + + /* End */ + return 0; +} + +/* +ڿ ˰ . +ϸũ . ϸũ Ǯ. +*/ diff --git a/baekjoon/Src/Baekjoon/Solved/1343[GR].cpp b/baekjoon/Src/Baekjoon/Solved/1343[GR].cpp new file mode 100644 index 0000000..86333e8 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/1343[GR].cpp @@ -0,0 +1,59 @@ +#pragma warning(disable : 4996) +#include +#include + +int main(int argc, char* argv[]) { + /* Input */ + char board[51]; + scanf("%s", board); // '\0' . + + /* Calculate */ + int s = 0, e = 0; // start, end + bool isunable = false; // üũ. + while (true) { + /* e : e '.' Ȥ '\0' ġ .*/ + while (board[e] != '.' && board[e] != '\0') e++; + + /* X Ȧ */ + if ((e - s) % 2 == 1) { + isunable = true; + break; + } + /* X ¦(AAAA..AABB) */ + else if ((e - s) % 4 == 2) { + while (s < e - 2) board[s++] = 'A'; + while (s < e) board[s++] = 'B'; + } + /* X ¦(AAAA..AAAA) */ + else { + while (s < e) board[s++] = 'A'; + } + + /* ݺ Ż */ + if (board[e] == '\0') break; + + /* s, e */ + s++; + e++; + } + + /* Output */ + if (isunable == true) + printf("%d", -1); + else + printf("%s", board); + + /* End */ + return 0; +} + +/* +̿ Ǯ . + + ˰ ̿. + +[ٹ] +X ¦̸ A or B ִ. +X 4̻ ¦̸, A ִ ä, B ä ȴ. +(̷ ϸ ռ µȴ.) +*/ diff --git a/baekjoon/Src/Baekjoon/Solved/1406.cpp b/baekjoon/Src/Baekjoon/Solved/1406.cpp new file mode 100644 index 0000000..42ba498 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/1406.cpp @@ -0,0 +1,78 @@ +#include +#include +#include +using namespace std; + +int main(int argc, char* argv[]) { + /* Faster */ + ios::sync_with_stdio(0); + cin.tie(0); + cout.tie(0); + + /* Init & Init */ + list li; + list::iterator it = li.end(); + + string str; + cin >> str; + for (int i = 0; i < str.size(); i++) + li.push_back(str[i]); + + /* Command */ + int m; + cin >> m; + for (int i = 0; i < m; i++) { + /* Input */ + char c; + cin >> c; + + switch (c) { + /* L */ + case 'L': { + if (it == li.begin()) continue; + it--; + + break; + } + /* D */ + case 'D': { + if (it == li.end()) continue; + it++; + + break; + } + /* B */ + case 'B': { + if (it == li.begin()) continue; + it = li.erase(--it); + + break; + } + /* P */ + case 'P': { + char ch; + cin >> ch; + li.insert(it, ch); + + break; + } + } + } + + /* Output */ + for (auto i : li) + cout << i; + + /* Return */ + return 0; +} + +/* +커서의 위치 : abc 라는 문자열이 주어진 경우. +^a^b^c^ : ^가 커서가 위치할 수 있는 자리이다. + +li.erase(iter)는 iter가 가리키는 원소를 삭제한 후, +삭제한 원소의 다음 원소를 가리키는 iterator를 반환한다. +따라서, li.erase(--it); 가 아닌 +it = li.erase(--it); 를 통해 it값을 업데이트 해주어야 한다. +*/ diff --git a/baekjoon/Src/Baekjoon/Solved/1427.cpp b/baekjoon/Src/Baekjoon/Solved/1427.cpp new file mode 100644 index 0000000..de14dfb --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/1427.cpp @@ -0,0 +1,46 @@ +#include + +int CountingCipher(int num); +void BubbleSortDES(int* array, int len); + +int main(void) { + int Cipher, num; // Cipher는 입력한 수의 자릿수 + int arr[1000] = {0}; // arr[0] 은 10의 0승 자리, arr[1]은 10의 1승 자리, ... + + // printf("수를 입력하시오\n"); + scanf("%d", &num); + Cipher = CountingCipher(num); + + for (int i = 0; i < Cipher; i++) { + arr[i] = num % 10; + num /= 10; + } + // 여기까지 해서 배열에 각자리 숫자 입력 완료. + + BubbleSortDES(arr, Cipher); // Cipher == sizeof(arr) / sizeof(int) + + for (int i = 0; i < Cipher; i++) + printf("%d", arr[i]); + + return 0; +} + +int CountingCipher(int num) { + int i; // i 가 자릿수 + for (i = 0; num != 0; i++) + num /= 10; + return i; +} + +void BubbleSortDES(int* array, int len) // len == Cipher +{ + int temp; + + for (int j = 0; j < len - 1; j++) + for (int i = 0; i < len - 1 - j; i++) + if (array[i] < array[i + 1]) { + temp = array[i]; + array[i] = array[i + 1]; + array[i + 1] = temp; + } +} diff --git a/baekjoon/Src/Baekjoon/Solved/1439[GR].cpp b/baekjoon/Src/Baekjoon/Solved/1439[GR].cpp new file mode 100644 index 0000000..d1eb9be --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/1439[GR].cpp @@ -0,0 +1,31 @@ +#pragma warning(disable : 4996) +#include +#define min(a, b) (((a) < (b)) ? (a) : (b)) +using namespace std; + +char S[1000000] = {}; //'\0'. +int count[2] = {}; // count[0] : 0 -> 1 Ƚ. count[1] : 1 -> 0 Ƚ. + +int main(int argc, char* argv[]) { + /* Input */ + scanf("%s", S); + + /* Calculate */ + for (int i = 0; S[i] != '\0'; i++) // O(n) ð⵵. + if (S[i] != S[i + 1]) count[(S[i] == '0' ? 0 : 1)]++; + + printf("%d", min(count[0], count[1])); + + /* End */ + return 0; +} + +/* +[ٹ] + 0 -> 1 Ƚ . + 1 -> 0 Ƚ . + +0 or 1 -> null(='\0') Ƚ . + + ּڰ ã. +*/ diff --git a/baekjoon/Src/Baekjoon/Solved/14495.cpp b/baekjoon/Src/Baekjoon/Solved/14495.cpp new file mode 100644 index 0000000..1251c8a --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/14495.cpp @@ -0,0 +1,23 @@ +#pragma warning(disable : 4996) +#include + +long long memo[120]; + +long long fibo(int n) { + if (n <= 3) + return 1; + else if (memo[n] != 0) + return memo[n]; + else + return memo[n] = fibo(n - 1) + fibo(n - 3); +} + +int main(int argc, char* argv[]) { + int n; + + scanf("%d", &n); + + printf("%lld", fibo(n)); + + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/1463[DP]_BU.cpp b/baekjoon/Src/Baekjoon/Solved/1463[DP]_BU.cpp new file mode 100644 index 0000000..ffc7a73 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/1463[DP]_BU.cpp @@ -0,0 +1,30 @@ +/* Header */ +#pragma warning(disable : 4996) +#include +#include + +#define MIN2(a, b) (((a) < (b)) ? (a) : (b)) +#define MIN3(a, b, c) (((MIN2((a), (b))) < (c)) ? (MIN2((a), (b))) : (c)) + +/* Global Variable */ +int C[1000000] = {}; // cache + +/* Main */ +int main(int argc, char* argv[]) { + /* Է */ + int n; + scanf("%d", &n); + + /* Bottom Up = Tabulation */ + C[1] = 0; + for (int i = 2; i <= n; i++) + C[i] = MIN3((i % 3 == 0 ? C[i / 3] : INT_MAX), + (i % 2 == 0 ? C[i / 2] : INT_MAX), C[i - 1]) + + 1; + + /* */ + printf("%d", C[n]); + + /* */ + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/1463[DP]_TD.cpp b/baekjoon/Src/Baekjoon/Solved/1463[DP]_TD.cpp new file mode 100644 index 0000000..614ef3e --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/1463[DP]_TD.cpp @@ -0,0 +1,37 @@ +/* Header */ +#pragma warning(disable : 4996) +#include +#include + +#define MIN2(a, b) (((a) < (b)) ? (a) : (b)) +#define MIN3(a, b, c) (((MIN2((a), (b))) < (c)) ? (MIN2((a), (b))) : (c)) + +/* Global Variable */ +int C[1000000] = {}; // cache + +/* Function */ +int F(int n) { + if (n == 1) + return 0; + else if (C[n] != 0) + return C[n]; + else + return C[n] = MIN3((n % 3 == 0 ? F(n / 3) + 1 : INT_MAX), + (n % 2 == 0 ? F(n / 2) + 1 : INT_MAX), F(n - 1) + 1); +} + +/* Main */ +int main(int argc, char* argv[]) { + int n; + scanf("%d", &n); + printf("%d", F(n)); + + return 0; +} + +/* +1. F(n-1) ϹǷ, INT_MAX min Ǵ . +, INT_MAX ÷ο ʾƵ ȴ. + +2.TD Stack Overflow Ǯ̰ Ұϴ. +*/ diff --git a/baekjoon/Src/Baekjoon/Solved/14681.cpp b/baekjoon/Src/Baekjoon/Solved/14681.cpp new file mode 100644 index 0000000..896a6a8 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/14681.cpp @@ -0,0 +1,22 @@ +#include + +int main(int argc, char *argv[]) + +{ + int A, B = 0; + scanf("%d %d", &A, &B); + + if (A > 0 && B > 0) + printf("1"); + + else if (A < 0 && B > 0) + printf("2"); + + else if (A < 0 && B < 0) + printf("3"); + + else if (A > 0 && B < 0) + printf("4"); + + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/14916[DP]_BU.cpp b/baekjoon/Src/Baekjoon/Solved/14916[DP]_BU.cpp new file mode 100644 index 0000000..0131fb3 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/14916[DP]_BU.cpp @@ -0,0 +1,41 @@ +#pragma warning(disable : 4996) +#include +#include + +#define min(a, b) (((a) < (b)) ? (a) : (b)) + +int C[100001] = {}; +int V[2] = {2, 5}; + +int main(int argc, char* argv[]) { + /* Input */ + int n; + scanf("%d", &n); + + /* DP */ + // init + for (int i = 1; i <= n; i++) + C[i] = SHRT_MAX; + // DP + for (int i = 0; i <= 1; i++) + for (int j = 1; j <= n; j++) + C[j] = min(((j - V[i]) >= 0 ? (C[j - V[i]] + 1) : SHRT_MAX), C[j]); + + /* Output */ + printf("%d", C[n] == SHRT_MAX ? -1 : C[n]); + + /* End */ + return 0; +} + +/* +INT_MAX ü ״ , C[j - V[i]] + 1 INT_MAX + 1 +߻Ͽ ÷ο찡 ߻Ѵ. , ̻ϰ µǹǷ +SHRT_MAX Ѵ ־. +( ġ ּڰ 1̰, k ִ 10000̹Ƿ, + ִ ִ 10000 ̴. SHRT_MAX ص .) +*/ + +/* +2294 2 logic Ǭ. +*/ diff --git a/baekjoon/Src/Baekjoon/Solved/1517.cpp b/baekjoon/Src/Baekjoon/Solved/1517.cpp new file mode 100644 index 0000000..5f83e2d --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/1517.cpp @@ -0,0 +1,57 @@ +#pragma warning(disable : 4996) +#include +#include +#include + +long long swap = 0; + +void merge(int A[], int l, int m, int r) { + int i = l; + int j = m + 1; + int t = 0; + int* tmp = (int*)calloc(r - l + 1, sizeof(int)); + + while (i <= m && j <= r) { + if (A[i] <= A[j]) + tmp[t++] = A[i++]; + else + tmp[t++] = A[j++], swap += (m - i + 1); + } + + // swap += (m - i + 1) * (r - m); + + while (i <= m) tmp[t++] = A[i++]; + while (j <= r) tmp[t++] = A[j++]; + + for (int k = l; k <= r; k++) A[k] = tmp[k - l]; + + free(tmp); +} + +void merge_sort(int A[], int l, int r) { + if (l < r) { + int m = (l + r) / 2; + + merge_sort(A, l, m); + merge_sort(A, m + 1, r); + + merge(A, l, m, r); + } +} + +int main(void) { + int n; + scanf("%d", &n); + + int* A = (int*)calloc(n, sizeof(int)); + for (int i = 0; i < n; i++) scanf("%d", &A[i]); + + merge_sort(A, 0, n - 1); + + // for (int i = 0; i < n; i++) + // printf("%d\n", A[i]); + + printf("%lld", swap); + + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/1520.cpp b/baekjoon/Src/Baekjoon/Solved/1520.cpp new file mode 100644 index 0000000..4367d90 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/1520.cpp @@ -0,0 +1,32 @@ +#pragma warning(disable : 4996) +#include + +int memo[501][501]; +int count = 0; + +int path(int m, int n) { + if (m == 1 && n == 1) { + count++; + return; + } + + else { + } +} + +int main(void) { + int m, n; + scanf("%d %d", &m, &n); + + for (int i = 1; i <= m; i++) + for (int j = 1; j <= n; j++) scanf("%d", &memo[i][j]); + + for (int i = 0; i <= m; i++) { // Test + for (int j = 0; j <= n; j++) printf("%3d", memo[i][j]); + printf("\n"); + } + + path(m, n); + + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/1520[DP]_TD.cpp b/baekjoon/Src/Baekjoon/Solved/1520[DP]_TD.cpp new file mode 100644 index 0000000..b1a3e4d --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/1520[DP]_TD.cpp @@ -0,0 +1,61 @@ +/* Header */ +#pragma warning(disable : 4996) +#include + +/* Global */ +int M[502][502] = {}; // Է° 迭 +int C_arr[502][502] = {}; // Cache (-1 ʱȭ) +//'0 ʱȭ' 'idx 0, 501 Ȱ ũ⸦ 502 ' + +/* Function */ +void init(void) { + for (int i = 0; i < 502; i++) + for (int j = 0; j < 502; j++) C_arr[i][j] = -1; +} + +int C_func(int m, int n) { + /* Base Case */ + if (m == 1 && n == 1) return 1; + /* Memoization */ + else if (C_arr[m][n] != -1) + return C_arr[m][n]; + // ڿ C[3][5] 0 ǹǷ, Cache 迭 0 ʱȭϸ ȵȴ. + /* Inductive Step */ + else + return C_arr[m][n] = (M[m][n] < M[m - 1][n] ? C_func(m - 1, n) : 0) + + (M[m][n] < M[m + 1][n] ? C_func(m + 1, n) : 0) + + (M[m][n] < M[m][n - 1] ? C_func(m, n - 1) : 0) + + (M[m][n] < M[m][n + 1] ? C_func(m, n + 1) : 0); +} + +/* Main */ +int main(int argc, char* argv[]) { + /* Init */ + init(); + + /* Input */ + int M, N; + scanf("%d %d", &M, &N); + for (int i = 1; i <= M; i++) + for (int j = 1; j <= N; j++) scanf("%d", &M[i][j]); + + /* Debug */ + // printf("\n"); + // for (int i = 0; i <= M + 1; i++) { + // for (int j = 0; j <= N + 1; j++) + // printf("%3d", V[i][j]); + // printf("\n"); + // } + // printf("\n"); + + /* Output */ + printf("%d", C_func(M, N)); + + /* End */ + return 0; +} + +/* +¿ ̵ ־(ǿ ´´ٸ) +BU ̿ϱ⿡ δ . +*/ diff --git a/baekjoon/Src/Baekjoon/Solved/1520[DP]_TD_S.cpp b/baekjoon/Src/Baekjoon/Solved/1520[DP]_TD_S.cpp new file mode 100644 index 0000000..b359b53 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/1520[DP]_TD_S.cpp @@ -0,0 +1,35 @@ +#pragma warning(disable : 4996) +#include + +int V[502][502] = {}; // Է° 迭 +int C[502][502] = {}; // Cache (-1 ʱȭ) + +void init(void) { + for (int i = 0; i < 502; i++) + for (int j = 0; j < 502; j++) C[i][j] = -1; +} + +int F(int m, int n) { + if (m == 1 && n == 1) + return 1; + else if (C[m][n] != -1) + return C[m][n]; + else + return C[m][n] = (V[m][n] < V[m - 1][n] ? F(m - 1, n) : 0) + + (V[m][n] < V[m + 1][n] ? F(m + 1, n) : 0) + + (V[m][n] < V[m][n - 1] ? F(m, n - 1) : 0) + + (V[m][n] < V[m][n + 1] ? F(m, n + 1) : 0); +} + +int main(int argc, char* argv[]) { + init(); + + int M, N; + scanf("%d %d", &M, &N); + for (int i = 1; i <= M; i++) + for (int j = 1; j <= N; j++) scanf("%d", &V[i][j]); + + printf("%d", F(M, N)); + + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/1546.cpp b/baekjoon/Src/Baekjoon/Solved/1546.cpp new file mode 100644 index 0000000..3b261cb --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/1546.cpp @@ -0,0 +1,35 @@ +#pragma warning(disable : 4996) +#include +#include + +int max(int arr[], int n) { + int max = 0; + + for (int i = 0; i < n; i++) + if (arr[i] > max) max = arr[i]; + + return max; +} + +int main(void) { + int n, m = 0; + double sum = 0; + scanf("%d", &n); + + int* arrint = (int*)calloc(n, sizeof(int)); + double* arrdouble = (double*)calloc(n, sizeof(double)); + for (int i = 0; i < n; i++) scanf("%d", &arrint[i]); + + m = max(arrint, n); + + for (int i = 0; i < n; i++) { + // printf("arr[%d] = %d\n", i, arrint[i]); + arrdouble[i] = (double)arrint[i] / m * 100; + // printf("arr[%lf] = %lf\n", i, arrdouble[i]); + sum += arrdouble[i]; + } + + printf("%.3lf", (double)sum / n); + + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/15552.cpp b/baekjoon/Src/Baekjoon/Solved/15552.cpp new file mode 100644 index 0000000..383a8b7 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/15552.cpp @@ -0,0 +1,16 @@ +#pragma warning(disable : 4996) +#include + +int main(int argc, char* argv[]) { + int num; + int a, b; + + scanf("%d", &num); + + for (int i = 0; i < num; i++) { + scanf("%d %d", &a, &b); + printf("%d\n", a + b); + } + + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/15596.cpp b/baekjoon/Src/Baekjoon/Solved/15596.cpp new file mode 100644 index 0000000..922920f --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/15596.cpp @@ -0,0 +1,7 @@ +long long sum(int* a, int n) { + long long sum = 0; + + for (int i = 0; i < n; i++) sum += a[i]; + + return sum; +} diff --git a/baekjoon/Src/Baekjoon/Solved/15988[DP].cpp b/baekjoon/Src/Baekjoon/Solved/15988[DP].cpp new file mode 100644 index 0000000..be48e32 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/15988[DP].cpp @@ -0,0 +1,28 @@ +/* 9095 Ʈ (Ʈ 9 .) */ +#pragma warning(disable : 4996) +#include + +long long cache[1000001] = {0, 1, 2, 4}; + +int main(int argc, char* argv[]) { + /* Input */ + int T; + scanf("%d", &T); + + /* Calculate */ + for (int i = 0; i < T; i++) { + /* Input */ + int n; + scanf("%d", &n); + + /* Calculate */ + for (int i = 4; i <= n; i++) + cache[i] = (cache[i - 1] + cache[i - 2] + cache[i - 3]) % 1000000009; + + /* Output */ + printf("%lld\n", cache[n]); + } + + /* End */ + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/15989[DP].cpp b/baekjoon/Src/Baekjoon/Solved/15989[DP].cpp new file mode 100644 index 0000000..7d24936 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/15989[DP].cpp @@ -0,0 +1,31 @@ +/* 9095 Ʈ (Ʈ 9 .) */ +/* 1 ( ξ ) */ +#pragma warning(disable : 4996) +#include + +int main(int argc, char* argv[]) { + /* Input */ + int T; + scanf("%d", &T); + + /* Calculate */ + for (int i = 0; i < T; i++) { + /* Init */ + int C[10001] = {1}; + + /* Input */ + int n; + scanf("%d", &n); + + /* Calculate */ + for (int j = 1; j <= 3; j++) + for (int k = 1; k <= n; k++) + C[k] += (k - j >= 0 ? C[k - j] : 0); + + /* Output */ + printf("%d\n", C[n]); + } + + /* End */ + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/16120[DP].cpp b/baekjoon/Src/Baekjoon/Solved/16120[DP].cpp new file mode 100644 index 0000000..48b8904 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/16120[DP].cpp @@ -0,0 +1,50 @@ +#include +#include +using namespace std; + +int main(int argc, char* argv[]) { + /* Faster */ + ios::sync_with_stdio(0); + cin.tie(0); + cout.tie(0); + + /* Init */ + string str; + cin >> str; + int cnt = 0; // 'P' Ÿ Ƚ. + + /* Calculate */ + for (int i = 0; i < str.size(); i++) { + if (cnt < 2) { + if (str[i] == 'P') { + cnt++; + } else if (str[i] == 'A') { + cout << "NP"; + return 0; + } + } else if (cnt >= 2) { + if (str[i] == 'P') { + cnt++; + } else if (str[i] == 'A') { + if (str[i + 1] == 'P') { + cnt--; + i++; + } else if (str[i + 1] == 'A') { + cout << "NP"; + return 0; + } + } + } + } + + /* Output */ + if (cnt == 1) + cout << "PPAP"; + else + cout << "NP"; + + /* End */ + return 0; +} + +/* ϸũ . */ diff --git a/baekjoon/Src/Baekjoon/Solved/1620[mapset].cpp b/baekjoon/Src/Baekjoon/Solved/1620[mapset].cpp new file mode 100644 index 0000000..e6345ca --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/1620[mapset].cpp @@ -0,0 +1,45 @@ +#include +#include +#include +#include +using namespace std; + +int main(int argc, char* argv[]) { + /* Faster */ + ios::sync_with_stdio(0); + cin.tie(0); + cout.tie(0); + + /* Init */ + map ns; + map sn; + + /* Input */ + int n, m; + cin >> n >> m; + for (int i = 1; i <= n; i++) { + string str; + cin >> str; + + ns.insert(make_pair(i, str)); + sn.insert(make_pair(str, i)); + } + + while (m--) { + string str; + cin >> str; + + if (isdigit(str.front())) + cout << ns.find(stoi(str))->second << '\n'; + else + cout << sn.find(str)->second << '\n'; + } + + /* Return */ + return 0; +} + +/* +https://nanyoungkim.tistory.com/159 +https://hagisilecoding.tistory.com/41 +*/ diff --git a/baekjoon/Src/Baekjoon/Solved/16395[DP]_TD.cpp b/baekjoon/Src/Baekjoon/Solved/16395[DP]_TD.cpp new file mode 100644 index 0000000..ba62fc0 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/16395[DP]_TD.cpp @@ -0,0 +1,27 @@ +#pragma warning(disable : 4996) +#include + +int Cache[31][31] = {}; + +int C(int n, int k) { + if (k == 0 || k == n) + return 1; + else if (Cache[n][k] != 0) + return Cache[n][k]; + else + return Cache[n][k] = Cache[n][n - k] = C(n - 1, k - 1) + C(n - 1, k); +} + +int main(int argc, char* argv[]) { + int n, k; + scanf("%d %d", &n, &k); + + printf("%d", C(n - 1, k - 1)); + + return 0; +} + +/* +ð⵵ Down : ĽĮ ﰢ Ī. +⵵ Down : Cache 迭 ũ ̱. +*/ diff --git a/baekjoon/Src/Baekjoon/Solved/1676[Math].cpp b/baekjoon/Src/Baekjoon/Solved/1676[Math].cpp new file mode 100644 index 0000000..d372591 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/1676[Math].cpp @@ -0,0 +1,51 @@ +/* Ǯ 1 */ +#include +#include +using namespace std; + +int main(int argc, char* argv[]) { + /* Faster */ + ios::sync_with_stdio(0); + cin.tie(0); + cout.tie(0); + + /* Init */ + int arr[2] = {}; // μ 2, 5 . + int n; + cin >> n; + + /* Calculation */ + for (int i = 1; i <= n; i++) { + int x = i; + + while (((x % 2) == 0) || ((x % 5) == 0)) { + if (x % 2 == 0) { // 2 . + arr[0]++; + x /= 2; + } else if (x % 5 == 0) { // 5 . + arr[1]++; + x /= 5; + } + } + } + + /* Output */ + cout << min(arr[0], arr[1]); + + /* Return */ + return 0; +} + +/* Ǯ 2 */ +#include +using namespace std; + +int main() { + int n; + cin >> n; + cout << (n / 5) + (n / 25) + (n / 125); +} + +/* +https://torbjorn.tistory.com/247 +*/ diff --git a/baekjoon/Src/Baekjoon/Solved/1700[GR].cpp b/baekjoon/Src/Baekjoon/Solved/1700[GR].cpp new file mode 100644 index 0000000..daf37bc --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/1700[GR].cpp @@ -0,0 +1,139 @@ +#pragma warning(disable : 4996) +#include +#include +#include +using namespace std; + +class Multitap { + private: + int* socket; + int len; + int pocnt; // plug out count + + public: + /* Constructer & Destructor */ + Multitap(int len) { + socket = new int[len]{}; // 0=false ʱȭ. + this->len = len; + pocnt = 0; + } + ~Multitap() { delete[] socket; } + /* Func */ + void plugin( + int plug) { // Ƽ idx ÷׸ ȴ´. + for (int idx = 0; idx < len; idx++) + if (socket[idx] == 0) { + socket[idx] = plug; + break; + } + } + void plugout(int plug) { + for (int idx = 0; idx < len; idx++) + if (socket[idx] == plug) { + socket[idx] = 0; + break; + } + pocnt++; + } + bool isplug(int plug) const { // Ƽǿ plug plug ֳ Ȯ + for (int idx = 0; idx < len; idx++) + if (socket[idx] == plug) return true; + return false; + } + bool isfull( + void) const { // Ƽ ϳ false, true + for (int i = 0; i < len; i++) + if (socket[i] == false) return false; + return true; + } + int getpocnt(void) const { return pocnt; } + int opt(int job_q[], int len, int idx) const { + /* Init */ + int maxidx = 0; + + /* OPT */ + for (int i = 0, max = 0; i < this->len; i++) { // i° socket + int tmp = INT_MAX; + + for (int j = idx + 1; j < len; j++) + if (socket[i] == job_q[j]) { + tmp = j - idx; + break; + } + + if (max < tmp) { + max = tmp; + maxidx = socket[i]; + } + } + + /* End */ + return maxidx; + } + /* Debug */ + void getstatus(void) const { + printf("\nMul "); + for (int i = 0; i < this->len; i++) printf("%d ", i); + printf("\nPlu "); + for (int i = 0; i < this->len; i++) printf("%d ", socket[i]); + printf("\n\n"); + } +}; + +int main(int argc, char* argv[]) { + /* Input */ + int N, K; + scanf("%d %d", &N, &K); + + Multitap multitap(N); + int* job_q = new int[K]{}; // 0 ʱȭ. + + for (int i = 0; i < K; i++) scanf("%d", &job_q[i]); + + ///* Debug */ + // for (int i = 0; i < K; i++) + // printf("%2d ", i); + // printf("\n"); + // for (int i = 0; i < K; i++) + // printf("%2d ", job_q[i]); + // printf("\n\n"); + + /* Scheduling */ + for (int i = 0; i < K; i++) { + /* Ƽǿ job_q[i] شϴ ÷װ */ + if (!multitap.isplug(job_q[i])) { + /* plugout */ + if (multitap.isfull()) // Ƽ ִ 쿡 plugout + multitap.plugout(multitap.opt(job_q, K, i)); + + /* plugin */ + multitap.plugin(job_q[i]); + } + + ///* debug */ + // printf("queue : %d, pocnt : %d", job_q[i], multitap.getpocnt()); + // multitap.getstatus(); + } + + /* OUtput */ + printf("%d", multitap.getpocnt()); + + /* End */ + delete[] job_q; + return 0; +} + +/* +OS locality . +OS ü ˰. +( ̻ ˰ OPT ˰ ϴ ̴.) +pocnt ᱹ page fault ߻ Ƚ̴. + +ݷ +[INPUT] +2 18 +1 2 3 4 3 4 3 4 3 4 1 2 1 2 1 2 1 2 + +[OUTPUT] +4 +*/ diff --git "a/baekjoon/Src/Baekjoon/Solved/17106[\352\265\254\353\215\260\352\270\260].cpp" "b/baekjoon/Src/Baekjoon/Solved/17106[\352\265\254\353\215\260\352\270\260].cpp" new file mode 100644 index 0000000..7e2d6d5 --- /dev/null +++ "b/baekjoon/Src/Baekjoon/Solved/17106[\352\265\254\353\215\260\352\270\260].cpp" @@ -0,0 +1,7 @@ +/* +.#..# +##### +..#.# +.##.# +#..## +*/ diff --git a/baekjoon/Src/Baekjoon/Solved/1717.cpp b/baekjoon/Src/Baekjoon/Solved/1717.cpp new file mode 100644 index 0000000..c52f01d --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/1717.cpp @@ -0,0 +1,47 @@ +#pragma warning(disable : 4996) +#include +#include + +void DS_make_set(int p[], int u) { p[u] = u; } + +int DS_find_set(int p[], int u) { // Root Node ã. + if (u == p[u]) + return u; + else + return p[u] = DS_find_set(p, p[u]); +} + +void DS_Union(int p[], int u, int v) { + p[DS_find_set(p, v)] = DS_find_set(p, u); +} + +void print_test(int p[], int n) { // Test + for (int i = 0; i <= n; i++) printf("%d ", p[i]); + printf("\n"); +} + +int main(int argc, char* argv[]) { + int n, m = 0; + scanf("%d %d", &n, &m); + + int* p = (int*)calloc(n + 1, sizeof(int)); + for (int i = 0; i <= n; i++) DS_make_set(p, i); + + // print_test(p, n); //Test + + for (int i = 0; i < m; i++) { + int op, buf1, buf2 = 0; + scanf("%d %d %d", &op, &buf1, &buf2); + + if (op == 0) DS_Union(p, buf1, buf2); + if (op == 1) + printf("%s\n", + DS_find_set(p, buf1) == DS_find_set(p, buf2) ? "YES" : "NO"); + + // print_test(p, n); + } + + free(p); + + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/17219[mapset].cpp b/baekjoon/Src/Baekjoon/Solved/17219[mapset].cpp new file mode 100644 index 0000000..bfbd2d0 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/17219[mapset].cpp @@ -0,0 +1,35 @@ +#include +#include +#include +using namespace std; + +int main(int argc, char* argv[]) { + /* Faster */ + ios::sync_with_stdio(0); + cin.tie(0); + cout.tie(0); + + /* Init */ + unordered_map sp; // site pw + + /* Input */ + int n, m; + cin >> n >> m; + while (n--) { + string site; + cin >> site; + string pw; + cin >> pw; + + sp.insert(make_pair(site, pw)); + } + while (m--) { + string site; + cin >> site; + + cout << sp.find(site)->second << '\n'; + } + + /* Return */ + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/17263.cpp b/baekjoon/Src/Baekjoon/Solved/17263.cpp new file mode 100644 index 0000000..8691e43 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/17263.cpp @@ -0,0 +1,50 @@ +#pragma warning(disable : 4996) +#include +#include +#include + +void merge(int A[], int l, int m, int r) { + int i = l; + int j = m + 1; + int t = 0; + int* tmp = (int*)calloc(r - l + 1, sizeof(int)); + + while (i <= m && j <= r) { + if (A[i] < A[j]) + tmp[t++] = A[i++]; + else + tmp[t++] = A[j++]; + } + + while (i <= m) tmp[t++] = A[i++]; + while (j <= r) tmp[t++] = A[j++]; + + for (int k = l; k <= r; k++) A[k] = tmp[k - l]; + + free(tmp); +} + +void merge_sort(int A[], int l, int r) { + if (l < r) { + int m = (l + r) / 2; + + merge_sort(A, l, m); + merge_sort(A, m + 1, r); + + merge(A, l, m, r); + } +} + +int main(void) { + int n; + scanf("%d", &n); + + int* A = (int*)calloc(n, sizeof(int)); + for (int i = 0; i < n; i++) scanf("%d", &A[i]); + + merge_sort(A, 0, n - 1); + + printf("%d", A[n - 1]); + + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/17404_easy.cpp b/baekjoon/Src/Baekjoon/Solved/17404_easy.cpp new file mode 100644 index 0000000..73cc4c1 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/17404_easy.cpp @@ -0,0 +1,64 @@ +/* 좀 더 간단한 풀이 : 0번 idx 기본세팅. 1번 idx부터 DP 계산 시작. */ +#pragma warning(disable : 4996) +#include +#include +#include +#define INF (INT_MAX / 2) +using namespace std; + +int table_src[1000][3] = {}; // R=0, G=1, B=2 + +int main(int argc, char* argv[]) { + /* Input */ + int N; + scanf("%d", &N); + for (int i = 0; i < N; i++) + scanf("%d %d %d", &table_src[i][0], &table_src[i][1], &table_src[i][2]); + + /* DP */ + int ans = INF; + for (int i = 0; i < 3; i++) { + /* Init */ + int table_dp[1000][3] = {}; + + /* i번 집에 지정된 색 이외의 색은 MAX로 지정하여 dp할때 선택되지 않도록 함. */ + table_dp[0][(i) % 3] = table_src[0][(i) % 3]; + table_dp[0][(i + 1) % 3] = INF; + table_dp[0][(i + 2) % 3] = INF; + + /* DP */ + for (int j = 1; j < N; j++) { + table_dp[j][0] = table_src[j][0] + min(table_dp[j - 1][1], table_dp[j - 1][2]); + table_dp[j][1] = table_src[j][1] + min(table_dp[j - 1][0], table_dp[j - 1][2]); + table_dp[j][2] = table_src[j][2] + min(table_dp[j - 1][0], table_dp[j - 1][1]); + } + + /* 최솟값 선택 */ + ans = min({ans, table_dp[N - 1][(i + 1) % 3], table_dp[N - 1][(i + 2) % 3]}); + + ///* Debug */ + // for (int i = 0; i < N; i++) { + // for (int j = 0; j < 3; j++) + // printf("%12d", table_dp[i][j]); + // printf("\n"); + // } + // printf("\n"); + } + + /* Output */ + printf("%d", ans); + + /* End */ + return 0; +} + +/* +Bottom Up 방식으로 풀었다. +Top Down 방식으로도 풀 수 있을지 고민해보자. +*/ + +/* +1149 문제와 세트문제이다. +1149번 문제는 선형배치였다면, 17404번 문제는 원형배치이다. +종이참고. +*/ diff --git a/baekjoon/Src/Baekjoon/Solved/17404_hard.cpp b/baekjoon/Src/Baekjoon/Solved/17404_hard.cpp new file mode 100644 index 0000000..95c622d --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/17404_hard.cpp @@ -0,0 +1,58 @@ +/* 좀 더 복잡한 풀이 : 0, 1번 idx 기본세팅. 2번 idx부터 DP 계산 시작. */ +#pragma warning(disable : 4996) +#include +#include +#include +using namespace std; + +int table_src[1000][3] = {}; // R=0, G=1, B=2 + +int main(int argc, char* argv[]) { + /* Input */ + int N; + scanf("%d", &N); + for (int i = 0; i < N; i++) + scanf("%d %d %d", &table_src[i][0], &table_src[i][1], &table_src[i][2]); + + /* DP */ + int ans = INT_MAX; + for (int i = 0; i < 3; i++) { + int table_dp[1000][3] = {table_src[0][0], table_src[0][1], table_src[0][2]}; + + table_dp[1][(i) % 3] = INT_MAX; + table_dp[1][(i + 1) % 3] = table_dp[0][(i) % 3] + table_src[1][(i + 1) % 3]; + table_dp[1][(i + 2) % 3] = table_dp[0][(i) % 3] + table_src[1][(i + 2) % 3]; + + for (int j = 2; j < N; j++) { + table_dp[j][0] = table_src[j][0] + min(table_dp[j - 1][1], table_dp[j - 1][2]); + table_dp[j][1] = table_src[j][1] + min(table_dp[j - 1][0], table_dp[j - 1][2]); + table_dp[j][2] = table_src[j][2] + min(table_dp[j - 1][0], table_dp[j - 1][1]); + } + + ans = min({ans, table_dp[N - 1][(i + 1) % 3], table_dp[N - 1][(i + 2) % 3]}); + + ///* Debug */ + // for (int i = 0; i < N; i++) { + // for (int j = 0; j < 3; j++) + // printf("%12d", table_dp[i][j]); + // printf("\n"); + // } + // printf("\n"); + } + + /* Output */ + printf("%d", ans); + + /* End */ + return 0; +} + +/* +Bottom Up 방식으로 풀었다. +Top Down 방식으로도 풀 수 있을지 고민해보자. +*/ + +/* +1149 문제와 세트문제이다. +1149번 문제는 선형배치였다면, 17404번 문제는 원형배치이다. +*/ diff --git a/baekjoon/Src/Baekjoon/Solved/1764[mapset].cpp b/baekjoon/Src/Baekjoon/Solved/1764[mapset].cpp new file mode 100644 index 0000000..d6fa450 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/1764[mapset].cpp @@ -0,0 +1,44 @@ +#include +#include +#include +using namespace std; + +int main(int argc, char* argv[]) { + /* Faster */ + ios::sync_with_stdio(0); + cin.tie(0); + cout.tie(0); + + /* Init */ + map ma; + + /* Input */ + int n, m; + cin >> n >> m; + int count = 0; + + /* N */ + while (n--) { + string str; + cin >> str; + ma.insert(make_pair(str, false)); + } + + /* M */ + while (m--) { + string str; + cin >> str; + if (ma.find(str) != ma.end()) { // ϴ + ma.find(str)->second = true; + count++; + } + } + + /* Output */ + cout << count << '\n'; + for (auto i : ma) + if (i.second) cout << i.first << '\n'; + + /* Return */ + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/17845[DP]_BU.cpp b/baekjoon/Src/Baekjoon/Solved/17845[DP]_BU.cpp new file mode 100644 index 0000000..7d6db75 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/17845[DP]_BU.cpp @@ -0,0 +1,26 @@ +#pragma warning(disable : 4996) +#include +#include +using namespace std; + +int table[10001] = {}; + +int main(int argc, char* argv[]) { + /* Input & DP */ + int N, K; + scanf("%d %d", &N, &K); + + for (int i = 0; i < K; i++) { + int I, T; + scanf("%d %d", &I, &T); + + for (int i = N; i >= T; i--) + table[i] = max(table[i], table[i - T] + I); + } + + /* Output */ + printf("%d", table[N]); + + /* End */ + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/1789[GR].cpp b/baekjoon/Src/Baekjoon/Solved/1789[GR].cpp new file mode 100644 index 0000000..a889a5c --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/1789[GR].cpp @@ -0,0 +1,93 @@ +#pragma warning(disable : 4996) +#include +#include + +/* Ǯ : O(1) */ +int main(int argc, char* argv[]) { + long long S; + scanf("%lld", &S); // N N ִ + + printf("%lld", (long long)((sqrt(1 + 8 * S) - 1) / 2)); + + return 0; +} + +/* ٸ Ǯ1 : O(logN) */ +#pragma warning(disable : 4996) +#include + +int main(int argc, char* argv[]) { + long long S; + scanf("%lld", &S); + long long N; // N ִ + + for (N = 1; !(N * (N + 1) / 2 <= S && S <= N * (N + 3) / 2); N++) { + } + + printf("%lld", N); + + return 0; +} + +/* +S unsigned int ϸ, ȿ 8 * S ϴ ÷ο찡 +߻Ѵ. , long long ־ Ѵ. +*/ + +/* +̿ Ǯ . O(1)Ǯ , ̿. + +[ٹ] +ڿ 1 ʴ Ѵ. + , N ִ밡 ȴ. (׸ ) + +[˾ ] +Unsigned int 4294967295̴. + +[] +#. 2 +1[1] +2[3] -> [1] + 2 = 3̹Ƿ Ұ. + +, 1 + +#. 3 +1[1] +2[3] -> [1] + 2 = 3̹Ƿ . + +, 2 + +#. 4 +1[1] +2[3] +3[6] -> [3] + 3 = 6̹Ƿ Ұ. + +, 2 + +#. 5 +1[1] +2[3] +3[6] -> [3] + 3 = 6̹Ƿ Ұ. + +, 2 + +#. 6 +1[1] +2[3] +3[6] -> [3] + 3 = 6̹Ƿ . + +, 3 + +... +=============================== +1+...+(n) ~ 1+...+(n)+(n+1)-1 = +1+...+(n) ~ 1+...+(n)+(n) = +n*(n+1)/2 ~ n*(n+3)/2 + +1 : 001 ~ 002 +2 : 003 ~ 005 +3 : 006 ~ 009 +4 : 010 ~ 014 +... + +*/ diff --git a/baekjoon/Src/Baekjoon/Solved/18108.cpp b/baekjoon/Src/Baekjoon/Solved/18108.cpp new file mode 100644 index 0000000..f6dd0b5 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/18108.cpp @@ -0,0 +1,14 @@ +#include +using std::cin; +using std::cout; +using std::endl; + +int main(void) { + int gap = 2541 - 1998; + int y; + + cin >> y; + cout << y - gap; + + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/18258.cpp b/baekjoon/Src/Baekjoon/Solved/18258.cpp new file mode 100644 index 0000000..43ad698 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/18258.cpp @@ -0,0 +1,92 @@ +#include +#include +using namespace std; + +class queue { + private: + int* arr; + + int F; + int R; + + const int max = 2000001; + + public: + /* Constructor & Destructor */ + queue() : F(0), R(0) { + arr = new int[max](); + } + ~queue() { + delete[] arr; + } + /* Method */ + void push(int elem) { + arr[++R] = elem; + } + int pop(void) { + if (F == R) + return -1; + else + return arr[++F]; + } + int size(void) { + return R - F; + } + int empty(void) { + if (F == R) + return 1; + else + return 0; + } + int front(void) { + if (F == R) + return -1; + else + return arr[F + 1]; + } + int back(void) { + if (F == R) + return -1; + else + return arr[R]; + } +}; + +int main(int argc, char* argv[]) { + /* Faster */ + ios::sync_with_stdio(0); + cin.tie(0); + cout.tie(0); + + /* Init */ + queue q; + + /* Input */ + int N; + cin >> N; + for (int i = 0; i < N; i++) { + string str; + cin >> str; + + if (str == "push") { + int elem; + cin >> elem; + q.push(elem); + } else if (str == "pop") { + cout << q.pop() << '\n'; + } else if (str == "size") { + cout << q.size() << '\n'; + } else if (str == "empty") { + cout << q.empty() << '\n'; + } else if (str == "front") { + cout << q.front() << '\n'; + } else if (str == "back") { + cout << q.back() << '\n'; + } + } + + /* End */ + return 0; +} + +/* 원형 큐 이용 안함 */ diff --git a/baekjoon/Src/Baekjoon/Solved/1874[DS].cpp b/baekjoon/Src/Baekjoon/Solved/1874[DS].cpp new file mode 100644 index 0000000..08ae462 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/1874[DS].cpp @@ -0,0 +1,52 @@ +#include +#include +#include +using namespace std; + +int main(int argc, char* argv[]) { + /* Faster */ + ios::sync_with_stdio(0); + cin.tie(0); + cout.tie(0); + + /* Init */ + int n; + cin >> n; + + queue seq; + for (int i = 0; i < n; i++) { + int tmp; + cin >> tmp; + seq.push(tmp); + } + + stack s; + queue ans; + + /* Calculate */ + for (int i = 1; !seq.empty();) { + if (s.empty()) { + s.push(i++); + ans.push('+'); + } else if (s.top() == seq.front()) { + seq.pop(); + s.pop(); + ans.push('-'); + } else if (s.top() < seq.front()) { + s.push(i++); + ans.push('+'); + } else if (s.top() > seq.front()) { + cout << "NO"; + return 0; + } + } + + /* Output */ + while (!ans.empty()) { + cout << ans.front() << '\n'; + ans.pop(); + } + + /* End */ + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/1913.cpp b/baekjoon/Src/Baekjoon/Solved/1913.cpp new file mode 100644 index 0000000..321b3bd --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/1913.cpp @@ -0,0 +1,62 @@ +#pragma warning(disable : 4996) +#include +#include + +int main(int argc, char* argv[]) { + /* N, key값 입력 받음 */ + int N; + scanf("%d", &N); + int key; + scanf("%d", &key); + + /* 2차원 동적배열 할당 */ + int** arr = (int**)calloc(N, sizeof(int*)); + for (int i = 0; i < N; i++) + arr[i] = (int*)calloc(N, sizeof(int)); + + /* 달팽이 채워넣기 */ + int col = N / 2; + int row = N / 2; + int num = 1; + + for (int i = 1; num <= N * N; i++) { + for (int j = 1; j <= (i + 1) / 2; j++) { + /* part1. 쓰기 */ + arr[col][row] = num++; + + /* part2. 위치 */ + /* UP */ + if (i % 4 == 1) + col--; + /* RIGHT */ + else if (i % 4 == 2) + row++; + /* DOWN */ + else if (i % 4 == 3) + col++; + /* LEFT */ + else if (i % 4 == 0) + row--; + } + } + + /* 출력_달팽이 */ + for (int i = 0; i < N; i++) { + for (int j = 0; j < N; j++) + printf("%d ", arr[i][j]); + printf("\n"); + } + + /* 출력_key값 위치 */ + for (int i = 0; i < N; i++) + for (int j = 0; j < N; j++) + if (key == arr[i][j]) + printf("%d %d", i + 1, j + 1); + + /* 마무리 */ + for (int i = 0; i < N; i++) + free(arr[i]); + free(arr); + + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/1918[DS].cpp b/baekjoon/Src/Baekjoon/Solved/1918[DS].cpp new file mode 100644 index 0000000..f51699e --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/1918[DS].cpp @@ -0,0 +1,86 @@ +#include +#include +#include +using namespace std; + +int getoprank(char op) { + switch (op) { + case '*': + case '/': + return 2; + case '+': + case '-': + return 1; + case '(': + return 0; + } + return -1; +} + +string infix_to_postfix(string infix) { + /* Init */ + stack op; + string postfix; + + /* Calculation */ + for (int i = 0; i < infix.size(); i++) { + /* Alphabet */ + if ('A' <= infix[i] && infix[i] <= 'Z') { + postfix.push_back(infix[i]); + } + /* Operator */ + else { + /* '(' */ + if (infix[i] == '(') { + op.push(infix[i]); + } + /* ')' */ + else if (infix[i] == ')') { + while (op.top() != '(') { + postfix.push_back(op.top()); + op.pop(); + } + op.pop(); + } + /* '*', '/', '+', '-' */ + else { + while (!op.empty() && (getoprank(op.top()) >= getoprank(infix[i]))) { + postfix.push_back(op.top()); + op.pop(); + } + op.push(infix[i]); + } + } + } + + while (!op.empty()) { + postfix.push_back(op.top()); + op.pop(); + } + + /* Return */ + return postfix; +} + +int main(int argc, char* argv[]) { + /* Faster */ + ios::sync_with_stdio(0); + cin.tie(0); + cout.tie(0); + + /* Init */ + string str; + getline(cin, str); + + /* Output */ + cout << infix_to_postfix(str) << '\n'; + + /* Return */ + return 0; +} + +/* +1918 1935 Ʈ . + . + ڷᱸ å . +*/ diff --git a/baekjoon/Src/Baekjoon/Solved/1920[DS].cpp b/baekjoon/Src/Baekjoon/Solved/1920[DS].cpp new file mode 100644 index 0000000..a3c9862 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/1920[DS].cpp @@ -0,0 +1,42 @@ +#include +#include +using namespace std; + +int main(int argc, char* argv[]) { + /* Faster */ + ios::sync_with_stdio(0); + cin.tie(0); + cout.tie(0); + + /* Init */ + unordered_set us; + + /* Input */ + int n; + cin >> n; + while (n--) { + int x; + cin >> x; + us.insert(x); + } + + int m; + cin >> m; + while (m--) { + int x; + cin >> x; + + if (us.find(x) == us.end()) // ã Ѱ + cout << '0' << '\n'; + else + cout << '1' << '\n'; + } + + /* Return */ + return 0; +} + +/* +https://blog.naver.com/PostView.nhn?blogId=yoochansong&logNo=222089528785&parentCategoryNo=&categoryNo=10&viewDate=&isShowPopularPosts=true&from=search\ +https://holicaz.tistory.com/5 +*/ diff --git a/baekjoon/Src/Baekjoon/Solved/1927[DS].cpp b/baekjoon/Src/Baekjoon/Solved/1927[DS].cpp new file mode 100644 index 0000000..5441d4d --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/1927[DS].cpp @@ -0,0 +1,39 @@ +#include +#include +using namespace std; + +int main(int argc, char* argv[]) { + /* Faster */ + ios::sync_with_stdio(0); + cin.tie(0); + cout.tie(0); + + /* Init */ + priority_queue, greater> pq; + + /* Input */ + int n; + cin >> n; + for (int i = 0; i < n; i++) { + /* Input */ + int x; + cin >> x; + + /* Calculation */ + if (x == 0) { + if (pq.empty()) { + cout << 0 << '\n'; + } else { + cout << pq.top() << '\n'; + pq.pop(); + } + } else { + pq.push(x); + } + } + + /* Return */ + return 0; +} + +/* 11279, 11286 Ʈ */ diff --git a/baekjoon/Src/Baekjoon/Solved/1929.cpp b/baekjoon/Src/Baekjoon/Solved/1929.cpp new file mode 100644 index 0000000..4b9f876 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/1929.cpp @@ -0,0 +1,42 @@ +#include +#include +using namespace std; + +bool sieve[1000001] = {true, true, false}; +// false인 경우가 소수. 즉, 0과 1은 소수에서 제외된다. + +int main(int argc, char* argv[]) { + /* Faster */ + ios::sync_with_stdio(0); + cin.tie(0); + cout.tie(0); + + /* Input */ + int M, N; + cin >> M >> N; + + /* Sieve of Eratosthenes */ + for (int i = 2; i <= (int)sqrt(N); i++) + for (int j = 2 * i; j <= N; j += i) + if (!sieve[j]) sieve[j] = true; + + /* Output */ + for (int i = M; i <= N; i++) + if (!sieve[i]) cout << i << '\n'; + + /* Return */ + return 0; +} + +/* +에라토스테네스의 체 + +... +N = 100~120 : 10까지만 확인 +N = 121~143 : 11까지만 확인 +N = 144~168 : 12까지만 확인 +N = 169~195 : 13까지만 확인 +N = 196~224 : 14까지만 확인 +... + +*/ diff --git a/baekjoon/Src/Baekjoon/Solved/1931.cpp b/baekjoon/Src/Baekjoon/Solved/1931.cpp new file mode 100644 index 0000000..2095060 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/1931.cpp @@ -0,0 +1,64 @@ +#pragma warning(disable : 4996) +#include +#include +#include +#include + +typedef struct { + unsigned int start; + unsigned int end; +} Conf; + +int compare(const Conf& a, const Conf& b) { + if (a.end == b.end) + return a.start < b.start; + else + return a.end < b.end; +} + +void activity_selection(Conf* arr, int n) { + std::queue q; + q.push(0); + int last = 0; + int count = 1; + + for (int i = 1; i < n; i++) { + if (arr[last].end <= arr[i].start) { + q.push(i); + last = i; + count++; + } + } + + ///* Test */ + // while (!q.empty()) { + // printf("%d | ", q.front()); + // q.pop(); + // } + // printf("\n"); + + printf("%d", count); +} + +int main(void) { + /* Input */ + int n; + scanf("%d", &n); + + Conf* arr = (Conf*)calloc(n, sizeof(Conf)); + for (int i = 0; i < n; i++) scanf("%u %u", &arr[i].start, &arr[i].end); + + ///* Test */ + // for (int i = 0; i < n; i++) + // printf("%d = start:%u, end:%u\n", i, arr[i].start, arr[i].end); + + std::sort(arr, arr + n, compare); + + ///* Test */ + // for (int i = 0; i < n; i++) + // printf("%d = start:%u, end:%u\n", i, arr[i].start, arr[i].end); + + activity_selection(arr, n); + + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/1934.cpp b/baekjoon/Src/Baekjoon/Solved/1934.cpp new file mode 100644 index 0000000..3d679ae --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/1934.cpp @@ -0,0 +1,24 @@ +#include + +int main(void) { + int num1, num2, MAX, MIN, Count; + + scanf("%d", &Count); + + for (int j = 1; j <= Count; j++) { + scanf("%d %d", &num1, &num2); + + if (num1 > num2) + MAX = num1, MIN = num2; + else + MAX = num2, MIN = num1; + + for (int i = 1; 1; i++) { + if ((MAX * i) % MIN == 0) { + printf("%d\n", MAX * i); + break; + } + } + } + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/1935[DS].cpp b/baekjoon/Src/Baekjoon/Solved/1935[DS].cpp new file mode 100644 index 0000000..5c4aa6e --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/1935[DS].cpp @@ -0,0 +1,54 @@ +#include +#include +#include +using namespace std; + +int main(int argc, char* argv[]) { + /* Faster */ + ios::sync_with_stdio(0); + cin.tie(0); + cout.tie(0); + + /* Init */ + stack val; + + int N; + cin >> N; + string postfix; + cin >> postfix; + int alphabet[26] = {}; + for (int i = 0; i < N; i++) cin >> alphabet[i]; + + /* Calculation */ + for (int i = 0; i < postfix.size(); i++) { + /* Alphatbet */ + if ('A' <= postfix[i] && postfix[i] <= 'Z') { + val.push(alphabet[postfix[i] - 'A']); + } + /* Operator */ + else { + double val1 = val.top(); + val.pop(); + double val2 = val.top(); + val.pop(); + + if (postfix[i] == '*') { + val.push(val2 * val1); + } else if (postfix[i] == '/') { + val.push(val2 / val1); + } else if (postfix[i] == '+') { + val.push(val2 + val1); + } else if (postfix[i] == '-') { + val.push(val2 - val1); + } + } + } + + /* Output */ + cout << fixed; + cout.precision(2); + cout << val.top(); + + /* Return */ + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/1966.cpp b/baekjoon/Src/Baekjoon/Solved/1966.cpp new file mode 100644 index 0000000..56c1b34 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/1966.cpp @@ -0,0 +1,81 @@ +#include +#include +#include +using namespace std; + +int main(int argc, char* argv[]) { + /* Faster */ + ios::sync_with_stdio(0); + cin.tie(0); + cout.tie(0); + + /* Input */ + int T; + cin >> T; + for (int i = 0; i < T; i++) { + /* Input */ + int N, M; + cin >> N >> M; + + /* Init */ + int arr[10] = {}; + queue> q; + bool flag = false; // 반복문 탈출을 위한 flag 변수 + + for (int j = 0; j < N; j++) { + int elem; + cin >> elem; + + arr[elem]++; + q.push(make_pair(elem, j == M)); + } + + /* Calculate */ + for (int j = 9; j >= 0; j--) { + while (arr[j] > 0) { + if (j == q.front().first) { + if (q.front().second == true) { + cout << N - q.size() + 1 << '\n'; + flag = true; + break; + } + + q.pop(); + arr[j]--; + } else { // j != q.front().first + q.push(q.front()); + q.pop(); + } + } + + if (flag == true) + break; + } + } + + /* End */ + return 0; +} + +/* + +//debug +for (int j = 0; j < 10; j++) { + cout.width(3); + cout << j << ' '; +} +cout << '\n'; +for (int j = 0; j < 10; j++) { + cout.width(3); + cout << arr[j] << ' '; +} +cout << '\n'; + +while (!q.empty()) { + cout.width(3); + cout << q.front().first << '&' << q.front().second << ' '; + q.pop(); +} +cout << '\n'; + +*/ diff --git a/baekjoon/Src/Baekjoon/Solved/1978.cpp b/baekjoon/Src/Baekjoon/Solved/1978.cpp new file mode 100644 index 0000000..fc3eb85 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/1978.cpp @@ -0,0 +1,21 @@ +#include + +int main(void) { + int PN[100] = {0}; + int num, count = 0; + scanf("%d", &num); + + for (int i = 0; i < num; i++) + scanf("%d", &PN[i]); + + for (int i = 0; PN[i] != 0; i++) { + for (int j = 2; j <= PN[i]; j++) + if (PN[i] % j == 0) { + if (PN[i] == j) + count++; + break; + } + } + printf("%d", count); + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/1991.cpp b/baekjoon/Src/Baekjoon/Solved/1991.cpp new file mode 100644 index 0000000..a8dc67c --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/1991.cpp @@ -0,0 +1,67 @@ +#include +using namespace std; + +/* Struct */ +struct node { + char left; + char right; +}; + +/* Global */ +node tree[26]; // A(0)~Z(26) 까지 저장. + +/* Fuction */ +void preorder(char root) { + if (root != '.') { + cout << root; + preorder(tree[root - 'A'].left); + preorder(tree[root - 'A'].right); + } +} + +void inorder(char root) { + if (root != '.') { + inorder(tree[root - 'A'].left); + cout << root; + inorder(tree[root - 'A'].right); + } +} + +void postorder(char root) { + if (root != '.') { + postorder(tree[root - 'A'].left); + postorder(tree[root - 'A'].right); + cout << root; + } +} + +/* Main */ +int main(int argc, char* argv[]) { + /* Faster */ + ios::sync_with_stdio(0); + cin.tie(0); + cout.tie(0); + + /* Input & Init */ + int n; + cin >> n; + for (int i = 0; i < n; i++) { + /* Input */ + char root, left, right; + cin >> root >> left >> right; + /* Tree */ + tree[root - 'A'].left = left; + tree[root - 'A'].right = right; + } + + /* Output */ + preorder('A'); + cout << '\n'; + inorder('A'); + cout << '\n'; + postorder('A'); + cout << '\n'; + + /* Return */ + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/2108.cpp b/baekjoon/Src/Baekjoon/Solved/2108.cpp new file mode 100644 index 0000000..4995b5a --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/2108.cpp @@ -0,0 +1 @@ +/*ٸ ǰ.*/ \ No newline at end of file diff --git a/baekjoon/Src/Baekjoon/Solved/2164.cpp b/baekjoon/Src/Baekjoon/Solved/2164.cpp new file mode 100644 index 0000000..7c9f301 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/2164.cpp @@ -0,0 +1,32 @@ +#include +#include +using namespace std; + +int main(int argc, char* argv[]) { + /* Faster */ + ios::sync_with_stdio(0); + cin.tie(0); + cout.tie(0); + + /* Init */ + queue q; + + /* Input */ + int N; + cin >> N; + + /* Calculate */ + 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(); + + /* End */ + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/2178[Graph].cpp b/baekjoon/Src/Baekjoon/Solved/2178[Graph].cpp new file mode 100644 index 0000000..68e5afb --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/2178[Graph].cpp @@ -0,0 +1,99 @@ +/* BFS for Maze */ +#include +#include +#include +using namespace std; + +int main(int argc, char* argv[]) { + /* Faster */ + ios::sync_with_stdio(0); + std::cin.tie(0); + std::cout.tie(0); + + /* Input & Init */ + int n, m; + cin >> n >> m; + + int dist[100][100] = {}; + bool visit[100][100] = {}; + char maze[100][100] = {}; + for (int i = 0; i < n; i++) cin >> maze[i]; + + pair T(n - 1, m - 1); // T ǥ + queue> q; // + + /* BFS for Maze */ + // Init + visit[0][0] = true; + q.push(make_pair(0, 0)); + + // BFS + while (!q.empty()) { + /* Init */ + int x = q.front().first; + int y = q.front().second; + q.pop(); + + /* Up */ + if (x - 1 >= 0 ? (maze[x - 1][y] == '1') && (visit[x - 1][y] == false) + : false) { + dist[x - 1][y] = dist[x][y] + 1; + visit[x - 1][y] = true; + q.push(make_pair(x - 1, y)); + } + /* Down */ + if (x + 1 <= n - 1 ? (maze[x + 1][y] == '1') && (visit[x + 1][y] == false) + : false) { + dist[x + 1][y] = dist[x][y] + 1; + visit[x + 1][y] = true; + q.push(make_pair(x + 1, y)); + } + /* Left */ + if (y - 1 >= 0 ? (maze[x][y - 1] == '1') && (visit[x][y - 1] == false) + : false) { + dist[x][y - 1] = dist[x][y] + 1; + visit[x][y - 1] = true; + q.push(make_pair(x, y - 1)); + } + /* Right */ + if (y + 1 <= m - 1 ? (maze[x][y + 1] == '1') && (visit[x][y + 1] == false) + : false) { + dist[x][y + 1] = dist[x][y] + 1; + visit[x][y + 1] = true; + q.push(make_pair(x, y + 1)); + } + + /* Debug */ + // std::cout << '\n'; + // for (int i = 0; i < n; i++) { + // for (int j = 0; j < m; j++) { + // std::cout << maze[i][j]; + // } + // std::cout << ' '; + // for (int j = 0; j < m; j++) { + // std::cout << visit[i][j]; + // } + // std::cout << ' '; + // for (int j = 0; j < m; j++) { + // std::cout << dist[i][j] + 1; + // } + // std::cout << '\n'; + // } + // queue> _q; _q = q; + // std::cout << "" << '\n'; + // while (!_q.empty()) { + // std::cout << '(' << _q.front().first << ' ' << _q.front().second << ')' + //<< '\n'; _q.pop(); + // } + } + + /* Output */ + std::cout << dist[T.first][T.second] + 1; + + /* Return */ + return 0; +} + +/* +ڷᱸ ð Ǭ ϴ. +*/ diff --git a/baekjoon/Src/Baekjoon/Solved/2292.cpp b/baekjoon/Src/Baekjoon/Solved/2292.cpp new file mode 100644 index 0000000..7c9f301 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/2292.cpp @@ -0,0 +1,32 @@ +#include +#include +using namespace std; + +int main(int argc, char* argv[]) { + /* Faster */ + ios::sync_with_stdio(0); + cin.tie(0); + cout.tie(0); + + /* Init */ + queue q; + + /* Input */ + int N; + cin >> N; + + /* Calculate */ + 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(); + + /* End */ + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/2293[DP]_BU.cpp b/baekjoon/Src/Baekjoon/Solved/2293[DP]_BU.cpp new file mode 100644 index 0000000..d0f9281 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/2293[DP]_BU.cpp @@ -0,0 +1,22 @@ +#pragma warning(disable : 4996) +#include + +int C[10001] = {1}; +int V[100] = {}; + +int main(int argc, char* argv[]) { + /* Input */ + int n, k; + scanf("%d %d", &n, &k); + for (int i = 0; i < n; i++) scanf("%d", &V[i]); + + /* DP */ + for (int i = 0; i < n; i++) + for (int j = 0; j <= k; j++) C[j] += (j >= V[i] ? C[j - V[i]] : 0); + + /* Output */ + printf("%d", C[k]); + + /* End */ + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/2293[DP]_TD.cpp b/baekjoon/Src/Baekjoon/Solved/2293[DP]_TD.cpp new file mode 100644 index 0000000..d015308 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/2293[DP]_TD.cpp @@ -0,0 +1,41 @@ +#pragma warning(disable : 4996) +#include +#include + +int F(int V[], int k, int L, int R) { + /* Base Case */ + if (k == 0) + return 1; + else if (L == R) { + if (k % V[R] == 0) + return 1; + else + return 0; + } + + /* Inductive Step */ + int sum = 0; + for (int i = 0; i <= k / V[L]; i++) sum += F(V, k - (V[L] * i), L + 1, R); + + return sum; +} + +int main(int argc, char* argv) { + /* Input */ + int n, k; + scanf("%d %d", &n, &k); + + int* V = (int*)calloc(n + 1, sizeof(int)); + for (int i = 1; i <= n; i++) scanf("%d", &V[i]); + + /* Output */ + printf("%d", F(V, k, 1, n)); + + /* End */ + free(V); + return 0; +} + +/* +1. int ڷ ǥ ִ -2^31 ~ 2^31 +*/ diff --git a/baekjoon/Src/Baekjoon/Solved/2294[DP]_BU.cpp b/baekjoon/Src/Baekjoon/Solved/2294[DP]_BU.cpp new file mode 100644 index 0000000..cc13766 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/2294[DP]_BU.cpp @@ -0,0 +1,38 @@ +#pragma warning(disable : 4996) +#include +#include + +#define min(a, b) (((a) < (b)) ? (a) : (b)) + +int C[10001] = {}; +int V[100] = {}; + +int main(int argc, char* argv[]) { + /* Input */ + int n, k; + scanf("%d %d", &n, &k); + for (int i = 0; i < n; i++) scanf("%d", &V[i]); + + /* DP */ + // init + for (int i = 1; i <= k; i++) C[i] = SHRT_MAX; + // DP + for (int i = 0; i < n; i++) + for (int j = 1; j <= k; j++) + C[j] = min(((j - V[i]) >= 0 ? (C[j - V[i]] + 1) : SHRT_MAX), C[j]); + + /* Output */ + printf("%d", C[k] == SHRT_MAX ? -1 : C[k]); + + /* End */ + return 0; +} + +/* +INT_MAX ü ״ , C[j - V[i]] + 1 INT_MAX + 1 +߻Ͽ ÷ο찡 ߻Ѵ. , ̻ϰ µǹǷ +SHRT_MAX Ѵ ־. +( ġ ּڰ 1̰, k ִ 10000̹Ƿ, + ִ ִ 10000 ̴. SHRT_MAX ص +.) +*/ diff --git a/baekjoon/Src/Baekjoon/Solved/2438.cpp b/baekjoon/Src/Baekjoon/Solved/2438.cpp new file mode 100644 index 0000000..0baac2d --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/2438.cpp @@ -0,0 +1,14 @@ +#include + +int main(void) { + int num; + + scanf("%d", &num); + + for (int i = 1; i <= num; i++) { + for (int j = 1; j <= i; j++) + printf("*"); + printf("\n"); + } + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/2439.cpp b/baekjoon/Src/Baekjoon/Solved/2439.cpp new file mode 100644 index 0000000..0826685 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/2439.cpp @@ -0,0 +1,15 @@ +#include + +int main(void) { + int num; + scanf("%d", &num); + + for (int i = 1; i <= num; i++) { + for (int j = 1; j <= num - i; j++) + printf(" "); + for (int k = 1; k <= i; k++) + printf("*"); + printf("\n"); + } + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/2440.cpp b/baekjoon/Src/Baekjoon/Solved/2440.cpp new file mode 100644 index 0000000..f48d8a0 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/2440.cpp @@ -0,0 +1,13 @@ +#include + +int main(void) { + int n; + scanf("%d", &n); + + for (int i = 0; i < n; i++) { + for (int j = n - i; j >= 1; j--) + printf("*"); + printf("\n"); + } + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/2441.cpp b/baekjoon/Src/Baekjoon/Solved/2441.cpp new file mode 100644 index 0000000..c28a891 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/2441.cpp @@ -0,0 +1,15 @@ +#include + +int main(void) { + int n; + scanf("%d", &n); + + for (int i = 0; i < n; i++) { + for (int j = n - i; j < n; j++) + printf(" "); + for (int j = n - i; j >= 1; j--) + printf("*"); + printf("\n"); + } + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/24416[DP].cpp b/baekjoon/Src/Baekjoon/Solved/24416[DP].cpp new file mode 100644 index 0000000..a5d7fcf --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/24416[DP].cpp @@ -0,0 +1,39 @@ +#pragma warning(disable : 4996) +#include + +int count_fibo1 = 0; +int count_fibo2 = 0; + +int fibo1(int n) { + if (n == 1 || n == 2) { + count_fibo1++; + return 1; + } else { + return (fibo1(n - 1) + fibo1(n - 2)); + } +} + +int fibo2(int n) { + int fibo[41] = {0, 1, 1}; + + for (int i = 3; i <= n; i++) { + count_fibo2++; + fibo[i] = fibo[i - 1] + fibo[i - 2]; + } + + return fibo[n]; +} + +int main(int argc, char* argv[]) { + int n; + scanf("%d", &n); + + fibo1(n); + fibo2(n); + + printf("%d %d", count_fibo1, count_fibo2); + + return 0; +} + +/* ̿ Ǯ̸ ʾҴ. */ diff --git a/baekjoon/Src/Baekjoon/Solved/2442.cpp b/baekjoon/Src/Baekjoon/Solved/2442.cpp new file mode 100644 index 0000000..07955ed --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/2442.cpp @@ -0,0 +1,24 @@ +#pragma warning(disable : 4996) +#include + +int main(int argc, char* argv[]) { + int n; + scanf("%d", &n); + + for (int i = 1; i <= n; i++) { + /* 공백 찍기 */ + for (int j = 1; j <= n - i; j++) { + printf(" "); + } + + /* 별 찍기 */ + for (int j = 1; j <= (2 * i) - 1; j++) { + printf("*"); + } + + /* 개행 */ + printf("\n"); + } + + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/2443.cpp b/baekjoon/Src/Baekjoon/Solved/2443.cpp new file mode 100644 index 0000000..0c76e6b --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/2443.cpp @@ -0,0 +1,24 @@ +#pragma warning(disable : 4996) +#include + +int main(int argc, char* argv[]) { + int n; + scanf("%d", &n); + + for (int i = n; i >= 1; i--) { + /* 공백 찍기 */ + for (int j = 1; j <= n - i; j++) { + printf(" "); + } + + /* 별 찍기 */ + for (int j = 1; j <= (2 * i) - 1; j++) { + printf("*"); + } + + /* 개행 */ + printf("\n"); + } + + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/2444.cpp b/baekjoon/Src/Baekjoon/Solved/2444.cpp new file mode 100644 index 0000000..517c509 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/2444.cpp @@ -0,0 +1,41 @@ +#pragma warning(disable : 4996) +#include + +int main(int argc, char* argv[]) { + int n; + scanf("%d", &n); + + for (int i = 1; i <= n - 1; i++) { // n에서 n-1로 값 변경. + + /* 공백 찍기 */ + for (int j = 1; j <= n - i; j++) { + printf(" "); + } + + /* 별 찍기 */ + for (int j = 1; j <= (2 * i) - 1; j++) { + printf("*"); + } + + /* 개행 */ + printf("\n"); + } + + for (int i = n; i >= 1; i--) { // 여기의 n을 n-1로 변경해도 됨. + + /* 공백 찍기 */ + for (int j = 1; j <= n - i; j++) { + printf(" "); + } + + /* 별 찍기 */ + for (int j = 1; j <= (2 * i) - 1; j++) { + printf("*"); + } + + /* 개행 */ + printf("\n"); + } + + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/2445.cpp b/baekjoon/Src/Baekjoon/Solved/2445.cpp new file mode 100644 index 0000000..5ce3338 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/2445.cpp @@ -0,0 +1,43 @@ +#pragma warning(disable : 4996) +#include + +int main(int argc, char* argv[]) { + int N; + scanf("%d", &N); + + for (int i = 1; i <= N; i++) { + /* 왼쪽 별 찍기 */ + for (int j = 1; j <= i; j++) + printf("*"); + + /* 공백 찍기 */ + for (int j = 1; j <= 2 * (N - i); j++) + printf(" "); + + /* 오른쪽 별 찍기 */ + for (int j = 1; j <= i; j++) + printf("*"); + + /* 개행 */ + printf("\n"); + } + + for (int i = N - 1; i >= 1; i--) { + /* 왼쪽 별 찍기 */ + for (int j = 1; j <= i; j++) + printf("*"); + + /* 공백 찍기 */ + for (int j = 1; j <= 2 * (N - i); j++) + printf(" "); + + /* 오른쪽 별 찍기 */ + for (int j = 1; j <= i; j++) + printf("*"); + + /* 개행 */ + printf("\n"); + } + + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/2446.cpp b/baekjoon/Src/Baekjoon/Solved/2446.cpp new file mode 100644 index 0000000..a0ecad7 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/2446.cpp @@ -0,0 +1,44 @@ +#pragma warning(disable : 4996) +#include + +int main(int argc, char* argv[]) { + int n; + scanf("%d", &n); + + /*2443번 문제*/ + for (int i = n; i >= 1; i--) { // 여기의 1을 2로 변경해도 된다. + + /* 공백 찍기 */ + for (int j = 1; j <= n - i; j++) { + printf(" "); + } + + /* 별 찍기 */ + for (int j = 1; j <= (2 * i) - 1; j++) { + printf("*"); + } + + /* 개행 */ + printf("\n"); + } + + /*2442번 문제*/ + for (int i = 2; i <= n; i++) { + // 2442번 문제와의 차이점 : 1을 2로 변경. (∵중복되는 줄 없애기 위함.) + + /* 공백 찍기 */ + for (int j = 1; j <= n - i; j++) { + printf(" "); + } + + /* 별 찍기 */ + for (int j = 1; j <= (2 * i) - 1; j++) { + printf("*"); + } + + /* 개행 */ + printf("\n"); + } + + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/2475.cpp b/baekjoon/Src/Baekjoon/Solved/2475.cpp new file mode 100644 index 0000000..d089f73 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/2475.cpp @@ -0,0 +1,15 @@ +#pragma warning(disable : 4996) +#include + +int main(int argc, char* argv[]) { + int n, sum = 0; + + for (int i = 0; i < 5; i++) { + scanf("%d", &n); + sum += n * n; + } + + printf("%d", sum % 10); + + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/2480.cpp b/baekjoon/Src/Baekjoon/Solved/2480.cpp new file mode 100644 index 0000000..89fd267 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/2480.cpp @@ -0,0 +1,22 @@ +#include +#define MAX3(a, b, c) (((a) > (b)) ? ((a) > (c) ? (a) : (c)) : ((b) > (c) ? (b) : (c))) + +int main(int argc, char* argv[]) { + int a, b, c = 0; + scanf("%d %d %d", &a, &b, &c); + + if (a == b && b == c) { + printf("%d", 10000 + (a * 1000)); + } else if (a == b || b == c || c == a) { + if (a == b) + printf("%d", 1000 + (a * 100)); + else if (b == c) + printf("%d", 1000 + (b * 100)); + else if (c == a) + printf("%d", 1000 + (c * 100)); + } else { + printf("%d", MAX3(a, b, c) * 100); + } + + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/2490.cpp b/baekjoon/Src/Baekjoon/Solved/2490.cpp new file mode 100644 index 0000000..fcb426e --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/2490.cpp @@ -0,0 +1,28 @@ +#include + +int main(void) { + int A, B, C, D, Sum = 0; + char Answer[3] = {0}; + + for (int i = 0; i < 3; i++) { + scanf("%d %d %d %d", &A, &B, &C, &D); + + Sum = A + B + C + D; + + if (Sum == 3) + Answer[i] = 'A'; + else if (Sum == 2) + Answer[i] = 'B'; + else if (Sum == 1) + Answer[i] = 'C'; + else if (Sum == 0) + Answer[i] = 'D'; + else + Answer[i] = 'E'; + } + + for (int i = 0; i < 3; i++) + printf("%c\n", Answer[i]); + + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/25083.cpp b/baekjoon/Src/Baekjoon/Solved/25083.cpp new file mode 100644 index 0000000..ab93f0d --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/25083.cpp @@ -0,0 +1,11 @@ +#include + +int main(int argc, char* argv[]) { + printf(" ,r'\"7\n"); + printf("r`-_ ,' ,/\n"); + printf(" \\. \". L_r'\n"); + printf(" `~\\/\n"); + printf(" |\n"); + printf(" |"); + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/2522.cpp b/baekjoon/Src/Baekjoon/Solved/2522.cpp new file mode 100644 index 0000000..282e886 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/2522.cpp @@ -0,0 +1,35 @@ +#pragma warning(disable : 4996) +#include + +int main(int argc, char* argv[]) { + int N; + scanf("%d", &N); + + /* 위쪽 */ + for (int i = 1; i <= N; i++) { + /* 공백 찍기 */ + for (int j = 1; j <= N - i; j++) + printf(" "); + + /* 별 찍기 */ + for (int j = 1; j <= i; j++) + printf("*"); + + printf("\n"); + } + + /* 아래쪽 */ + for (int i = N - 1; i >= 1; i--) { + /* 공백 찍기 */ + for (int j = 1; j <= N - i; j++) + printf(" "); + + /* 별 찍기 */ + for (int j = 1; j <= i; j++) + printf("*"); + + printf("\n"); + } + + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/2523.cpp b/baekjoon/Src/Baekjoon/Solved/2523.cpp new file mode 100644 index 0000000..a5a40a3 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/2523.cpp @@ -0,0 +1,29 @@ +#pragma warning(disable : 4996) +#include + +int main(int argc, char* argv[]) { + int N; + scanf("%d", &N); + + /* 위쪽 */ + for (int i = 1; i <= N; i++) { + /* 별 찍기 */ + for (int j = 1; j <= i; j++) + printf("*"); + + /* 개행 */ + printf("\n"); + } + + /* 아래쪽 */ + for (int i = N - 1; i >= 1; i--) { + /* 별 찍기 */ + for (int j = 1; j <= i; j++) + printf("*"); + + /* 개행 */ + printf("\n"); + } + + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/2525.cpp b/baekjoon/Src/Baekjoon/Solved/2525.cpp new file mode 100644 index 0000000..0982e6b --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/2525.cpp @@ -0,0 +1,17 @@ +#pragma warning(disable : 4996) +#include + +int main(void) { + int h = 0; + int m = 0; + int time = 0; + + scanf("%d %d", &h, &m); + scanf("%d", &time); + + int total = (60 * h) + m + time; + + printf("%d %d", (total / 60) % 24, total % 60); + + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/2527[Geo].cpp b/baekjoon/Src/Baekjoon/Solved/2527[Geo].cpp new file mode 100644 index 0000000..1a83d99 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/2527[Geo].cpp @@ -0,0 +1,52 @@ +#pragma warning(disable : 4996) +#include +using namespace std; + +typedef struct { + int x; + int y; +} Point; + +typedef struct { + Point ld; // Left Down + Point ru; // Right Up +} Square; + +int main(int argc, char* argv[]) { + for (int i = 0; i < 4; i++) { + /* Input */ + Square s1, s2; + scanf("%d %d %d %d %d %d %d %d", &s1.ld.x, &s1.ld.y, &s1.ru.x, &s1.ru.y, + &s2.ld.x, &s2.ld.y, &s2.ru.x, &s2.ru.y); + + /* Calculate */ + if ((s1.ru.x > s2.ld.x && s1.ru.y > s2.ld.y) && + (s1.ld.x < s2.ru.x && s1.ld.y < s2.ru.y)) + printf("a\n"); + else if ((s1.ru.x == s2.ld.x && s1.ru.y > s2.ld.y && + s1.ld.y < s2.ru.y) || // ʸ + (s1.ru.y == s2.ld.y && s1.ru.x > s2.ld.x && + s1.ld.x < s2.ru.x) || // ʸ + (s1.ld.x == s2.ru.x && s1.ld.y < s2.ru.y && + s1.ru.y > s2.ld.y) || // ʸ + (s1.ld.y == s2.ru.y && s1.ld.x < s2.ru.x && + s1.ru.x > s2.ld.x)) // Ʒʸ + printf("b\n"); + else if ((s1.ru.x == s2.ld.x && s1.ru.y == s2.ld.y) || // UR + (s1.ru.x == s2.ld.x && s1.ld.y == s2.ru.y) || // DR + (s1.ld.x == s2.ru.x && s1.ld.y == s2.ru.y) || // DL + (s1.ld.x == s2.ru.x && s1.ru.y == s2.ld.y)) // UL + printf("c\n"); + else + printf("d\n"); + } + + return 0; +} + +/* +̿ Ǯ . +->ܺη Ǯ̴ ǹ +ܺ->η Ǯ̴ ǹ ܼϴ. + ϸũ . +*/ diff --git a/baekjoon/Src/Baekjoon/Solved/25304.cpp b/baekjoon/Src/Baekjoon/Solved/25304.cpp new file mode 100644 index 0000000..e018771 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/25304.cpp @@ -0,0 +1,21 @@ +#pragma warning(disable : 4996) // visual studio scanf 오류 방지. +#include + +int main(int argc, char* argv[]) { + int X = 0; + int N, a, b; + + scanf("%d", &X); + scanf("%d", &N); + for (int i = 0; i < N; i++) { + scanf("%d %d", &a, &b); + X -= (a * b); + } + + if (X == 0) + printf("Yes"); + else if (X != 0) + printf("No"); + + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/25314.cpp b/baekjoon/Src/Baekjoon/Solved/25314.cpp new file mode 100644 index 0000000..53988b1 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/25314.cpp @@ -0,0 +1,21 @@ +#include +using namespace std; + +int main(int argc, char* argv[]) { + /* Faster */ + ios::sync_with_stdio(0); + cin.tie(0); + cout.tie(0); + + /* Input */ + int N; + cin >> N; + + /* Output */ + for (int i = 0; i < N / 4; i++) + cout << "long "; + cout << "int"; + + /* Return */ + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/2557.cpp b/baekjoon/Src/Baekjoon/Solved/2557.cpp new file mode 100644 index 0000000..eb9e565 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/2557.cpp @@ -0,0 +1,6 @@ +#include + +int main(void) { + printf("Hello World!"); + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/2558.cpp b/baekjoon/Src/Baekjoon/Solved/2558.cpp new file mode 100644 index 0000000..d7e4b8b --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/2558.cpp @@ -0,0 +1,12 @@ +#pragma warning(disable : 4996) +#include + +int main(int argc, char* argv[]) { + int a = 0, b = 0; + + scanf("%d %d", &a, &b); + + printf("%d", a + b); + + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/2562.cpp b/baekjoon/Src/Baekjoon/Solved/2562.cpp new file mode 100644 index 0000000..49a4ef3 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/2562.cpp @@ -0,0 +1,23 @@ +#pragma warning(disable : 4996) +#include +#include + +int main(void) { + int max = 0; + int idx = 0; + int arr[9] = {0}; + + for (int i = 0; i < 9; i++) + scanf("%d", &arr[i]); + + max = arr[0]; + for (int i = 1; i < 9; i++) + if (max < arr[i]) + max = arr[i]; + + for (int i = 0; i < 9; i++) + if (arr[i] == max) + printf("%d\n%d", max, i + 1); + + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/2563.cpp b/baekjoon/Src/Baekjoon/Solved/2563.cpp new file mode 100644 index 0000000..20e8d29 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/2563.cpp @@ -0,0 +1,43 @@ +#pragma warning(disable : 4996) +#include +#include + +int main(int argc, char* argv[]) { + /* 도화지 : false=0으로 초기화 */ + bool canvas[100][100] = {}; + + /* 입력_색종이 수=N */ + int N; + scanf("%d", &N); + + for (int i = 0; i < N; i++) { + /* 입력_행열 좌표 */ + int row, col; + scanf("%d %d", &row, &col); + + /* 색칠하기 */ + for (int j = col; j < col + 10; j++) + for (int k = row; k < row + 10; k++) + canvas[j][k] = true; + } + + /* 출력 */ + int count = 0; + + for (int i = 0; i < 100; i++) + for (int j = 0; j < 100; j++) + if (canvas[i][j] == true) count++; + + printf("%d", count); + + ///* debug */ + // printf("\n"); + // for (int i = 0; i < 100; i++) { + // for (int j = 0; j < 100; j++) + // printf("%d", canvas[i][j]); + // printf("\n"); + // } + + /* 마무리 */ + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/2566.cpp b/baekjoon/Src/Baekjoon/Solved/2566.cpp new file mode 100644 index 0000000..c9e97e2 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/2566.cpp @@ -0,0 +1,23 @@ +#pragma warning(disable : 4996) +#include +typedef struct { + int col; + int row; +} coordinate; + +int main(void) { + int arr[9][9]; + int max = 0; + coordinate c = {0}; + + for (int i = 0; i < 9; i++) + for (int j = 0; j < 9; j++) scanf("%d", &arr[i][j]); + + for (int i = 0; i < 9; i++) + for (int j = 0; j < 9; j++) + if (max < arr[i][j]) c.col = i, c.row = j, max = arr[i][j]; + + printf("%d\n%d %d", max, c.col + 1, c.row + 1); + + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/2577.cpp b/baekjoon/Src/Baekjoon/Solved/2577.cpp new file mode 100644 index 0000000..4ac5bd5 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/2577.cpp @@ -0,0 +1,19 @@ +#include + +int main(void) { + int Countnum[10] = {0}; + int A, B, C, Result; + + scanf("%d %d %d", &A, &B, &C); + Result = A * B * C; + + while (Result) { + Countnum[Result % 10]++; + Result /= 10; + } + + for (int i = 0; i < 10; i++) + printf("%d\n", Countnum[i]); + + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/2588.cpp b/baekjoon/Src/Baekjoon/Solved/2588.cpp new file mode 100644 index 0000000..6a07a4f --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/2588.cpp @@ -0,0 +1,28 @@ +#include +using std::cin; +using std::cout; +using std::endl; + +int main(void) { + int num1; + int num2; + + int three; + int four; + int five; + int result; + + cin >> num1 >> num2; + + three = num1 * (num2 % 10); + four = num1 * ((num2 / 10) % 10); + five = num1 * ((num2 / 10 / 10) % 10); + result = three + 10 * four + 100 * five; + + cout << three << endl + << four << endl + << five << endl + << result << endl; + + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/2675.cpp b/baekjoon/Src/Baekjoon/Solved/2675.cpp new file mode 100644 index 0000000..2399ba6 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/2675.cpp @@ -0,0 +1,30 @@ +#include + +int main(void) { + char str[1000] = {0}; + char repeat_str[1000] = {0}; + int repeat, startpos = 0, testcase; + + scanf("%d", &testcase); + + for (int j = 0; j < testcase; j++) { + scanf("%d", &repeat); + scanf("%s", str); + + for (int i = 0; str[i] != '\0'; i++) { + for (int k = 0; k < repeat; k++) + repeat_str[startpos + k] = str[i]; + startpos += repeat; + } + repeat_str[startpos++] = '!'; + } + + for (int i = 0; repeat_str[i] != '\0'; i++) { + if (repeat_str[i] == '!') + printf("\n"); + else + printf("%c", repeat_str[i]); + } + + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/2738[Math].cpp b/baekjoon/Src/Baekjoon/Solved/2738[Math].cpp new file mode 100644 index 0000000..12facc6 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/2738[Math].cpp @@ -0,0 +1,51 @@ +#include +using namespace std; + +int main(int argc, char* argv[]) { + /* Faster */ + ios::sync_with_stdio(0); + cin.tie(0); + cout.tie(0); + + /* Init & Input */ + int n, m; + cin >> n >> m; + + int** arr1 = new int*[n]; + int** arr2 = new int*[n]; + + for (int i = 0; i < n; i++) { + arr1[i] = new int[m]; + arr2[i] = new int[m]; + } + + for (int i = 0; i < n; i++) + for (int j = 0; j < m; j++) cin >> arr1[i][j]; + for (int i = 0; i < n; i++) + for (int j = 0; j < m; j++) cin >> arr2[i][j]; + + /* Calculation */ + for (int i = 0; i < n; i++) + for (int j = 0; j < m; j++) arr1[i][j] += arr2[i][j]; + + /* Output */ + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) cout << arr1[i][j] << ' '; + cout << '\n'; + } + + /* Delete */ + for (int i = 0; i < n; i++) { + delete[] arr1[i]; + delete[] arr2[i]; + } + delete[] arr1; + delete[] arr2; + + /* Return */ + return 0; +} + +/* +ܼ ̴. +*/ diff --git a/baekjoon/Src/Baekjoon/Solved/2739.cpp b/baekjoon/Src/Baekjoon/Solved/2739.cpp new file mode 100644 index 0000000..b7b8b4b --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/2739.cpp @@ -0,0 +1,11 @@ +#include + +int main(void) { + int N; + scanf("%d", &N); + + for (int i = 1; i <= 9; i++) + printf("%d * %d = %d\n", N, i, N * i); + + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/2740.cpp b/baekjoon/Src/Baekjoon/Solved/2740.cpp new file mode 100644 index 0000000..949906a --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/2740.cpp @@ -0,0 +1,43 @@ +#include +using namespace std; + +int mat1[100][100] = {}; +int mat2[100][100] = {}; + +int main(int argc, char* argv[]) { + /* Faster */ + ios::sync_with_stdio(0); + cin.tie(0); + cout.tie(0); + + /* Init */ + int n, m, k; + + /* Mat1 */ + cin >> n >> m; + for (int i = 0; i < n; i++) + for (int j = 0; j < m; j++) + cin >> mat1[i][j]; + + /* Mat2 */ + cin >> m >> k; + for (int i = 0; i < m; i++) + for (int j = 0; j < k; j++) + cin >> mat2[i][j]; + + /* Output */ + for (int _n = 0; _n < n; _n++) { + for (int _k = 0; _k < k; _k++) { + int mul = 0; + + for (int _m = 0; _m < m; _m++) + mul += mat1[_n][_m] * mat2[_m][_k]; + + cout << mul << ' '; + } + cout << '\n'; + } + + /* Return */ + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/2741.cpp b/baekjoon/Src/Baekjoon/Solved/2741.cpp new file mode 100644 index 0000000..cf825db --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/2741.cpp @@ -0,0 +1,11 @@ +#include + +int main(void) { + int n; + scanf("%d", &n); + + for (int i = 1; i <= n; i++) + printf("%d\n", i); + + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/2742.cpp b/baekjoon/Src/Baekjoon/Solved/2742.cpp new file mode 100644 index 0000000..66b0743 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/2742.cpp @@ -0,0 +1,12 @@ +#include + +int main(void) { + int input; + + scanf("%d", &input); + + for (int i = input; i >= 1; i--) + printf("%d\n", i); + + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/27433[math].cpp b/baekjoon/Src/Baekjoon/Solved/27433[math].cpp new file mode 100644 index 0000000..a50fe50 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/27433[math].cpp @@ -0,0 +1,26 @@ +#include +using namespace std; + +long long factorial(long long n) { + if (n == 0) + return 1; + else + return n * factorial(n - 1); +} + +int main(int argc, char* argv[]) { + /* Faster */ + ios::sync_with_stdio(0); + cin.tie(0); + cout.tie(0); + + /* Input */ + long long n; + cin >> n; + + /* Output */ + cout << factorial(n); + + /* Return */ + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/2743[STR].cpp b/baekjoon/Src/Baekjoon/Solved/2743[STR].cpp new file mode 100644 index 0000000..e587cd7 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/2743[STR].cpp @@ -0,0 +1,24 @@ +#include +#include +using namespace std; + +int main(int argc, char* argv[]) { + /* Faster */ + ios::sync_with_stdio(0); + cin.tie(0); + cout.tie(0); + + /* Input */ + string str; + cin >> str; + + /* Output */ + cout << str.size(); + + /* End */ + return 0; +} + +/* +string class Ǯ . +*/ diff --git a/baekjoon/Src/Baekjoon/Solved/2747.cpp b/baekjoon/Src/Baekjoon/Solved/2747.cpp new file mode 100644 index 0000000..800a3dc --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/2747.cpp @@ -0,0 +1,22 @@ +#pragma warning(disable : 4996) +#include + +long long memo[10001]; + +long long fibo(long long n) { + if (n <= 1) + return n; + else if (memo[n] != 0) + return memo[n]; + else + return memo[n] = fibo(n - 1) + fibo(n - 2); +} + +int main(void) { + long long n; + scanf("%lld", &n); + + printf("%lld", fibo(n)); + + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/2748.cpp b/baekjoon/Src/Baekjoon/Solved/2748.cpp new file mode 100644 index 0000000..82b6b09 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/2748.cpp @@ -0,0 +1,22 @@ +#pragma warning(disable : 4996) +#include + +long long memo[91]; + +long long fibo(int n) { + memo[0] = 0; + memo[1] = 1; + + for (int i = 2; i <= n; i++) memo[i] = memo[i - 1] + memo[i - 2]; + + return memo[n]; +} + +int main(void) { + int n; + scanf("%d", &n); + + printf("%lld", fibo(n)); + + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/2750.cpp b/baekjoon/Src/Baekjoon/Solved/2750.cpp new file mode 100644 index 0000000..a4093ca --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/2750.cpp @@ -0,0 +1,32 @@ +#include + +void Sort_Bubble(int* arr, int len) { + int temp; + + for (int j = 0; j < len; j++) { + for (int i = 0; i < len - j - 1; i++) { + if (arr[i] > arr[i + 1]) { + temp = arr[i]; + arr[i] = arr[i + 1]; + arr[i + 1] = temp; + } + } + } +} + +int main(void) { + int arr[1000] = {0}; + int inputN; + + scanf("%d", &inputN); + + for (int i = 0; i < inputN; i++) + scanf("%d", &arr[i]); + + Sort_Bubble(arr, inputN); + + for (int i = 0; i < inputN; i++) + printf("%d\n", arr[i]); + + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/2751.cpp b/baekjoon/Src/Baekjoon/Solved/2751.cpp new file mode 100644 index 0000000..96d731f --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/2751.cpp @@ -0,0 +1,50 @@ +#pragma warning(disable : 4996) +#include +#include +#include + +void merge(int A[], int l, int m, int r) { + int i = l; + int j = m + 1; + int t = 0; + int* tmp = (int*)calloc(r - l + 1, sizeof(int)); + + while (i <= m && j <= r) { + if (A[i] < A[j]) + tmp[t++] = A[i++]; + else + tmp[t++] = A[j++]; + } + + while (i <= m) tmp[t++] = A[i++]; + while (j <= r) tmp[t++] = A[j++]; + + for (int k = l; k <= r; k++) A[k] = tmp[k - l]; + + free(tmp); +} + +void merge_sort(int A[], int l, int r) { + if (l < r) { + int m = (l + r) / 2; + + merge_sort(A, l, m); + merge_sort(A, m + 1, r); + + merge(A, l, m, r); + } +} + +int main(void) { + int n; + scanf("%d", &n); + + int* A = (int*)calloc(n, sizeof(int)); + for (int i = 0; i < n; i++) scanf("%d", &A[i]); + + merge_sort(A, 0, n - 1); + + for (int i = 0; i < n; i++) printf("%d\n", A[i]); + + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/2752.cpp b/baekjoon/Src/Baekjoon/Solved/2752.cpp new file mode 100644 index 0000000..4e7330f --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/2752.cpp @@ -0,0 +1,38 @@ +#pragma warning(disable : 4996) +#include +#include +#include + +void optimized_bubble_sort(int A[], int n) { + int flag; + + for (int i = n - 1; i >= 1; i--) { + flag = 0; + for (int j = 0; j <= i - 1; j++) { + if (A[j] > A[j + 1]) { + int tmp = A[j]; + A[j] = A[j + 1]; + A[j + 1] = tmp; + flag = 1; + } + } + if (flag == 0) + return; + } +} + +int main(void) { + int n = 3; + // scanf("%d", &n); + + int* A = (int*)calloc(n, sizeof(int)); + for (int i = 0; i < n; i++) + scanf("%d", &A[i]); + + optimized_bubble_sort(A, n); + + for (int i = 0; i < n; i++) + printf("%d ", A[i]); + + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/2753.cpp b/baekjoon/Src/Baekjoon/Solved/2753.cpp new file mode 100644 index 0000000..bb19f4d --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/2753.cpp @@ -0,0 +1,24 @@ +#pragma warning(disable : 4996) +#include + +int Y(int n) { + if (n % 4 == 0) { + if (n % 100 == 0) { + if (n % 400 == 0) + return 1; + else + return 0; + } + return 1; + } else + return 0; +} + +int main(void) { + int n; + scanf("%d", &n); + + printf("%d", Y(n)); + + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/2775[DP]_BU.cpp b/baekjoon/Src/Baekjoon/Solved/2775[DP]_BU.cpp new file mode 100644 index 0000000..70c3c01 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/2775[DP]_BU.cpp @@ -0,0 +1,30 @@ +#pragma warning(disable : 4996) +#include + +int C[15][15] = {}; + +int main(int argc, char* argv[]) { + int T; + scanf("%d", &T); + for (int i = 0; i < T; i++) { + /* Input */ + int k, n; + scanf("%d %d", &k, &n); + + /* DP */ + for (int j = 0; j <= n; j++) C[0][j] = j; + + for (int j = 1; j <= k; j++) + for (int k = 1; k <= n; k++) C[j][k] = C[j - 1][k] + C[j][k - 1]; + + /* Output */ + printf("%d\n", C[k][n]); + } + + return 0; +} + +/* +0 : (0) 1 2 3 4 5 6 7 8 9 10 ... +1 : (0) 1 3 6 10 ... +*/ diff --git a/baekjoon/Src/Baekjoon/Solved/2798.cpp b/baekjoon/Src/Baekjoon/Solved/2798.cpp new file mode 100644 index 0000000..04246b2 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/2798.cpp @@ -0,0 +1,35 @@ +#pragma warning(disable : 4996) +#include +#include + +#define max(a, b) (((a) > (b)) ? (a) : (b)) + +int main(int argc, char* argv[]) { + /* 입력 */ + int N, M; + scanf("%d %d", &N, &M); + + int* arr = (int*)calloc(N, sizeof(int)); + for (int i = 0; i < N; i++) + scanf("%d", &arr[i]); + + /* 최대한 가까운 카드 3장 찾기 */ + int max_num = 0; + for (int i = 0; i < N - 2; i++) { + for (int j = i + 1; j < N - 1; j++) { + for (int k = j + 1; k < N; k++) { + /* 합이 M을 넘을 경우 */ + if (arr[i] + arr[j] + arr[k] > M) + continue; + max_num = max(max_num, arr[i] + arr[j] + arr[k]); + } + } + } + + /* 출력 */ + printf("%d", max_num); + + /* 마무리 */ + free(arr); + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/2839.cpp b/baekjoon/Src/Baekjoon/Solved/2839.cpp new file mode 100644 index 0000000..9dc0b42 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/2839.cpp @@ -0,0 +1,41 @@ +#pragma warning(disable : 4996) +#include +#include + +#define min(a, b) (((a) < (b)) ? (a) : (b)) + +int C[5001] = {}; +int V[2] = {3, 5}; + +int main(int argc, char* argv[]) { + /* Input */ + int n; + scanf("%d", &n); + + /* DP */ + // init + for (int i = 1; i <= n; i++) + C[i] = SHRT_MAX; + // DP + for (int i = 0; i <= 1; i++) + for (int j = 1; j <= n; j++) + C[j] = min(((j - V[i]) >= 0 ? (C[j - V[i]] + 1) : SHRT_MAX), C[j]); + + /* Output */ + printf("%d", C[n] == SHRT_MAX ? -1 : C[n]); + + /* End */ + return 0; +} + +/* +INT_MAX 자체를 그대로 사용할 경우, C[j - V[i]] + 1에서 INT_MAX + 1 값이 +발생하여 오버플로우가 발생한다. 따라서, 답이 이상하게 출력되므로 +SHRT_MAX로 무한대의 값을 설정해 주었다. +(동전의 가치의 최솟값은 1이고, k값의 최댓값은 10000이므로, +사용될 수 있는 동전의 최대 개수는 10000 이다. 따라서 SHRT_MAX를 사용해도 문제 없다.) +*/ + +/* +2294번 동전2 문제와 동일한 logic을 가지고 푼다. +*/ diff --git a/baekjoon/Src/Baekjoon/Solved/2869.cpp b/baekjoon/Src/Baekjoon/Solved/2869.cpp new file mode 100644 index 0000000..6814166 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/2869.cpp @@ -0,0 +1,12 @@ +#pragma warning(disable : 4996) +#include +#include + +int main(int argc, char* argv[]) { + int A, B, V; + scanf("%d %d %d", &A, &B, &V); + + printf("%d", (int)ceil((double)(V - B) / (A - B))); + + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/2884.cpp b/baekjoon/Src/Baekjoon/Solved/2884.cpp new file mode 100644 index 0000000..27c2ae3 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/2884.cpp @@ -0,0 +1,28 @@ +#pragma warning(disable : 4996) +#include +#include + +typedef struct { + int H; + int M; +} time; + +void time_minus(time* t, int M) { + if (t->M - M >= 0) + t->M = t->M - M; + else { + t->M = 60 - abs(t->M - M); + t->H - 1 < 0 ? t->H = 24 - abs(t->H - 1) : t->H -= 1; + } +} + +int main(int argc, char* argv[]) { + time t = {0}; + scanf("%d %d", &t.H, &t.M); + + time_minus(&t, 45); + + printf("%d %d\n", t.H, t.M); + + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/2908.cpp b/baekjoon/Src/Baekjoon/Solved/2908.cpp new file mode 100644 index 0000000..2752c5f --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/2908.cpp @@ -0,0 +1,35 @@ +#include + +int main(void) { + int A, B, Count = 0; + int Arev[3], Brev[3]; + + scanf("%d %d", &A, &B); + + while (A) { + Arev[Count++] = A % 10; + A /= 10; + } + + Count = 0; + + while (B) { + Brev[Count++] = B % 10; + B /= 10; + } + + for (int i = 0; i < 3; i++) { + if (Arev[i] == Brev[i]) + continue; + else if (Arev[i] < Brev[i]) { + for (int j = 0; j < 3; j++) + printf("%d", Brev[j]); + break; + } else { + for (int j = 0; j < 3; j++) + printf("%d", Arev[j]); + break; + } + } + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/2920.cpp b/baekjoon/Src/Baekjoon/Solved/2920.cpp new file mode 100644 index 0000000..de18f7a --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/2920.cpp @@ -0,0 +1,19 @@ +#pragma warning(disable : 4996) +#include + +int main(int argc, char* argv[]) { + int arr[8]; + for (int i = 0; i < 8; i++) + scanf("%d", &arr[i]); + + if (arr[0] == 1 && arr[1] == 2 && arr[2] == 3 && arr[3] == 4 && + arr[4] == 5 && arr[5] == 6 && arr[6] == 7 && arr[7] == 8) + printf("ascending"); + else if (arr[0] == 8 && arr[1] == 7 && arr[2] == 6 && arr[3] == 5 && + arr[4] == 4 && arr[5] == 3 && arr[6] == 2 && arr[7] == 1) + printf("descending"); + else + printf("mixed"); + + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/2941.cpp b/baekjoon/Src/Baekjoon/Solved/2941.cpp new file mode 100644 index 0000000..5f6468e --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/2941.cpp @@ -0,0 +1,50 @@ +#include + +int main(void) { + char str[102] = {0}; + int count = 0; + + scanf("%s", str); + + for (int i = 0; str[i] != '\0'; i++) { + if (str[i] == 'c') { + if (str[i + 1] == '=') + count++, i++; + + else if (str[i + 1] == '-') + count++, i++; + + else + count++; + } + + else if (str[i] == 'd') { + if (str[i + 1] == 'z' && str[i + 2] == '=') + count++, i += 2; + + else if (str[i + 1] == '-') + count++, i++; + + else + count++; + } + + else if (str[i] == 'l' && str[i + 1] == 'j') + count++, i++; + + else if (str[i] == 'n' && str[i + 1] == 'j') + count++, i++; + + else if (str[i] == 's' && str[i + 1] == '=') + count++, i++; + + else if (str[i] == 'z' && str[i + 1] == '=') + count++, i++; + + else + count++; + } + + printf("%d", count); + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/3003.cpp b/baekjoon/Src/Baekjoon/Solved/3003.cpp new file mode 100644 index 0000000..5c52713 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/3003.cpp @@ -0,0 +1,9 @@ +#pragma warning(disable : 4996) // visual studio scanf 오류 방지. +#include + +int main(int argc, char* argv[]) { + int king, queen, rook, bishop, knight, pawn; + scanf("%d %d %d %d %d %d", &king, &queen, &rook, &bishop, &knight, &pawn); + printf("%d %d %d %d %d %d\n", 1 - king, 1 - queen, 2 - rook, 2 - bishop, 2 - knight, 8 - pawn); + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/3009.cpp b/baekjoon/Src/Baekjoon/Solved/3009.cpp new file mode 100644 index 0000000..bcefdee --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/3009.cpp @@ -0,0 +1,50 @@ +#pragma warning(disable : 4996) +#include + +typedef struct { + int x; + int y; +} Point; + +// int main(int argc, char* argv[]) { +// Point pos; +// Point count[1001] = {}; +// +// for (int i = 0; i < 3; i++) { +// scanf("%d %d", &pos.x, &pos.y); +// count[pos.x].x++; count[pos.y].y++; +// } +// +// for (int i = 1; i <= 1000; i++) +// if (count[i].x == 1) +// printf("%d ", i); +// +// for (int i = 1; i <= 1000; i++) +// if (count[i].y == 1) +// printf("%d", i); +// +// return 0; +// } + +int main(int argc, char* argv[]) { + Point pos[3]; + + for (int i = 0; i < 3; i++) + scanf("%d %d", &pos[i].x, &pos[i].y); + + if (pos[0].x == pos[1].x) + printf("%d ", pos[2].x); + else if (pos[0].x == pos[2].x) + printf("%d ", pos[1].x); + else + printf("%d ", pos[0].x); + + if (pos[0].y == pos[1].y) + printf("%d", pos[2].y); + else if (pos[0].y == pos[2].y) + printf("%d", pos[1].y); + else + printf("%d", pos[0].y); + + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/3015[DS].cpp b/baekjoon/Src/Baekjoon/Solved/3015[DS].cpp new file mode 100644 index 0000000..6f5559c --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/3015[DS].cpp @@ -0,0 +1,97 @@ +#include +#include +#include +#include +using namespace std; + +typedef long long ll; + +int main(int argc, char* argv[]) { + /* Faster */ + ios::sync_with_stdio(0); + cin.tie(0); + cout.tie(0); + + /* Init & Input */ + ll ans = 0; + int n; + cin >> n; + + vector list(n); + for (auto& i : list) cin >> i; + stack> s; // val, cnt + + /* Calculation */ + for (auto i : list) { + int cnt = 1; + + while (!s.empty() && s.top().first <= i) { + if (s.top().first == i) cnt += s.top().second; + + ans += s.top().second; + s.pop(); + } + + if (!s.empty()) ans++; + + s.push(make_pair(i, cnt)); + } + + /* Output */ + cout << ans; + + /* Return */ + return 0; +} + +/* +https://www.acmicpc.net/board/view/116397 +https://www.acmicpc.net/board/view/108339 +https://mangu.tistory.com/115 +*/ + +#include +#include +#include +using namespace std; + +int main(int argc, char* argv[]) { + /* Faster */ + ios::sync_with_stdio(0); + cin.tie(0); + cout.tie(0); + + /* Init */ + vector list; + int pair = 0; + + /* Input */ + int n; + cin >> n; + for (int i = 0; i < n; i++) { + int x; + cin >> x; + list.push_back(x); + } + + /* Calculation */ + for (int i = 0; i < n - 1; i++) { + if (list[i] >= list[i + 1]) { + stack s; + + s.push(list[i + 1]); + for (int j = i + 2; j < n; j++) + if (s.top() <= list[j]) s.push(list[j]); + + pair += s.size(); + } else { + pair++; + } + } + + /* Output */ + cout << pair; + + /* Return */ + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/3052.cpp b/baekjoon/Src/Baekjoon/Solved/3052.cpp new file mode 100644 index 0000000..86678f5 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/3052.cpp @@ -0,0 +1,25 @@ +#pragma warning(disable : 4996) +#include +#include + +int main(int argc, char* argv[]) { + int input; + bool output[42] = {}; // 나머지에 해당하는 값 체크. + + /* 서로 다른 나머지 개수 세기 */ + for (int i = 0; i < 10; i++) { + scanf("%d", &input); + input %= 42; + output[input] = true; + } + + /* 출력 */ + int count = 0; + for (int i = 0; i < 42; i++) + if (output[i] == true) count++; + + printf("%d", count); + + /* 마무리 */ + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/3067.cpp b/baekjoon/Src/Baekjoon/Solved/3067.cpp new file mode 100644 index 0000000..fdb0586 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/3067.cpp @@ -0,0 +1,30 @@ +#pragma warning(disable : 4996) +#include + +int main(int argc, char* argv[]) { + int T; + scanf("%d", &T); + for (int i = 0; i < T; i++) { + /* Init */ + int C[10001] = {1}; + int V[20] = {}; + + /* Input */ + int N; + scanf("%d", &N); + for (int j = 0; j < N; j++) + scanf("%d", &V[j]); + int M; + scanf("%d", &M); + + /* DP */ + for (int i = 0; i < N; i++) + for (int j = 0; j <= M; j++) + C[j] += (j >= V[i] ? C[j - V[i]] : 0); + + /* Output */ + printf("%d\n", C[M]); + } + + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/4101.cpp b/baekjoon/Src/Baekjoon/Solved/4101.cpp new file mode 100644 index 0000000..a105456 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/4101.cpp @@ -0,0 +1,24 @@ +#include + +using namespace std; + +int main() { + /* Faster */ + ios::sync_with_stdio(0); + cin.tie(0), cout.tie(0); + + /* Variables*/ + int a = 0, b = 0; + + /* Input */ + while (true) { + cin >> a >> b; + + if (a == 0 && b == 0) break; + + cout << (a > b ? "Yes" : "No") << '\n'; + } + + /* Return */ + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/4153.cpp b/baekjoon/Src/Baekjoon/Solved/4153.cpp new file mode 100644 index 0000000..c80f1c3 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/4153.cpp @@ -0,0 +1,19 @@ +#pragma warning(disable : 4996) +#include + +int main(int argc, char* argv[]) { + int a, b, c; + + while (true) { + scanf("%d %d %d", &a, &b, &c); + if (a == 0 && b == 0 && c == 0) + break; + + if (a * a == b * b + c * c || b * b == a * a + c * c || c * c == a * a + b * b) + printf("right\n"); + else + printf("wrong\n"); + } + + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/4344.cpp b/baekjoon/Src/Baekjoon/Solved/4344.cpp new file mode 100644 index 0000000..6727d2f --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/4344.cpp @@ -0,0 +1,38 @@ +#pragma warning(disable : 4996) +#include + +int main(int argc, char* argv[]) { + int C; + scanf("%d", &C); + + for (int i = 0; i < C; i++) { + int grade[1000] = {}; + int avg = 0, count = 0; + int N; + scanf("%d", &N); + + /* 점수 총합 구하기 */ + for (int j = 0; j < N; j++) { + scanf("%d", &grade[j]); + avg += grade[j]; + } + + /* 평균 구하기 */ + avg /= N; + + /* 평균을 넘는 학생 수 구하기 */ + for (int j = 0; j < N; j++) + if (grade[j] > avg) + count++; + + /* 비율 출력하기 */ + printf("%.3f%%\n", (double)count / N * 100); + } + + return 0; +} + +/* +퍼센트(%) 기호 자체를 출력하기 위해서는 퍼센트 기호를 +"2개 중복"해 주어야 한다. +*/ diff --git a/baekjoon/Src/Baekjoon/Solved/4673.cpp b/baekjoon/Src/Baekjoon/Solved/4673.cpp new file mode 100644 index 0000000..6727d2f --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/4673.cpp @@ -0,0 +1,38 @@ +#pragma warning(disable : 4996) +#include + +int main(int argc, char* argv[]) { + int C; + scanf("%d", &C); + + for (int i = 0; i < C; i++) { + int grade[1000] = {}; + int avg = 0, count = 0; + int N; + scanf("%d", &N); + + /* 점수 총합 구하기 */ + for (int j = 0; j < N; j++) { + scanf("%d", &grade[j]); + avg += grade[j]; + } + + /* 평균 구하기 */ + avg /= N; + + /* 평균을 넘는 학생 수 구하기 */ + for (int j = 0; j < N; j++) + if (grade[j] > avg) + count++; + + /* 비율 출력하기 */ + printf("%.3f%%\n", (double)count / N * 100); + } + + return 0; +} + +/* +퍼센트(%) 기호 자체를 출력하기 위해서는 퍼센트 기호를 +"2개 중복"해 주어야 한다. +*/ diff --git a/baekjoon/Src/Baekjoon/Solved/4781[DP]_BU.cpp b/baekjoon/Src/Baekjoon/Solved/4781[DP]_BU.cpp new file mode 100644 index 0000000..e7b8996 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/4781[DP]_BU.cpp @@ -0,0 +1,49 @@ +#pragma warning(disable : 4996) +#include +#include +#include +using namespace std; + +int main(int argc, char* argv[]) { + while (true) { + /* Init */ + int table[10001] = {}; + // table ϸ, while Խ ʱȭ ȵȴ. + + /* Input */ + int n; + double m; + scanf("%d %lf", &n, &m); + int m_int = (int)(m * 100 + 0.5); + + /* Break */ + if (n == 0 && m == 0) break; + + /* DP */ + for (int i = 0; i < n; i++) { + int c; + double p; + scanf("%d %lf", &c, &p); + int p_int = (int)(p * 100 + 0.5); + + for (int j = p_int; j <= m_int; j++) + table[j] = max(table[j], table[j - p_int] + c); + } + + /* Output */ + printf("%d\n", table[m_int]); + } + + /* End */ + return 0; +} + +/* +double ڷ 100 ȯ, +εҼ Ȯ ȯ Ƿ, +0.5 ־ Ѵ. +*/ + +/* +ϸũ +*/ diff --git a/baekjoon/Src/Baekjoon/Solved/4949[DS].cpp b/baekjoon/Src/Baekjoon/Solved/4949[DS].cpp new file mode 100644 index 0000000..6584a25 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/4949[DS].cpp @@ -0,0 +1,63 @@ +#include +#include +#include +using namespace std; + +int main(int argc, char* argv[]) { + /* Faster */ + ios::sync_with_stdio(0); + cin.tie(0); + cout.tie(0); + + /* Input */ + while (true) { + /* Init */ + string str; + getline(cin, str); + if (str == ".") break; + + stack s; + + bool isno = false; // flag + + /* Calculate */ + for (int i = 0; i < str.size(); i++) { + if (str[i] == '(' || str[i] == '[') { + s.push(str[i]); + } else if (str[i] == ')' || str[i] == ']') { + if (s.empty() || str[i] == ')' && s.top() == '[' || + str[i] == ']' && s.top() == '(') { + isno = true; + break; + } else { + s.pop(); + } + } + } + + /* Output */ + if (!s.empty() || isno == true) + cout << "no" << '\n'; + else + cout << "yes" << '\n'; + } + + /* End */ + return 0; +} + +/* + +9012 Ǯ + +'(' ')' ƽŰڵ ̿, '[' ']' ƽŰڵ ̰ +ʾ, str[i] == ')' && s.top() == '[' || str[i] == ']' && s.top() == '(' +ڵ带 ۼ ۿ . + +[ݷ] +input : [)] +output : no + +ϸũ . + +*/ diff --git a/baekjoon/Src/Baekjoon/Solved/5397.cpp b/baekjoon/Src/Baekjoon/Solved/5397.cpp new file mode 100644 index 0000000..10e5bf2 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/5397.cpp @@ -0,0 +1,67 @@ +#include +#include +#include +using namespace std; + +int main(int argc, char* argv[]) { + /* Faster */ + ios::sync_with_stdio(0); + cin.tie(0); + cout.tie(0); + + /* Input */ + int n; + cin >> n; + for (int i = 0; i < n; i++) { + /* Init & Input */ + list li; + list::iterator it = li.begin(); + + string str; + cin >> str; + + /* Key Logger */ + for (auto j : str) { + /* Alphabet & Number */ + if (('A' <= j && j <= 'Z') || + ('a' <= j && j <= 'z') || + ('0' <= j && j <= '9')) { + li.insert(it, j); // 아래 코드와의 차이점을 알아야 한다. + // it = li.insert(it, j); + } + /* Backspace : '-' */ + else if (j == '-') { + if (it != li.begin()) + it = li.erase(--it); + } + /* Arrow : < */ + else if (j == '<') { + if (it != li.begin()) + it--; + } + /* Arrow : > */ + else if (j == '>') { + if (it != li.end()) + it++; + } + } + + /* Output */ + for (auto j : li) + cout << j; + cout << '\n'; + } + + /* Return */ + return 0; +} + +/* +li.insert(it, j); 일 경우, +Input : < +#include +#include +#include +using namespace std; + +int main(int argc, char* argv[]) { + /* Faster */ + ios::sync_with_stdio(0); + cin.tie(0); + cout.tie(0); + + /* Input */ + int t; + cin >> t; + for (int i = 0; i < t; i++) { + /* Init */ + deque dq; + + /* Input */ + string p; + cin >> p; + int n; + cin >> n; + + /* Parsing */ + string pars; + cin >> pars; + char num[3]; + int idx = 0; //'일', '십, 일', '백, 십, 일'의 자리 순서대로 저장. + + for (auto c : pars) { + /* '0' ~ '9' */ + if ('0' <= c && c <= '9') num[idx++] = c; + + /* ',' & ']' */ + else if (c == ',' || c == ']') { + int sum = 0; + for (int j = 0; idx != 0; j++) sum += (num[j] - '0') * (int)pow(10, (idx--) - 1); + if (sum != 0) dq.push_back(sum); + } + } + + /* Function */ + bool error = false; + bool FR = false; // false = Front & true = Rear + + for (auto c : p) { + /* 'R' */ + if (c == 'R') { + FR = !FR; + } + /* 'D' */ + else if (c == 'D') { + if (dq.empty()) + error = true; + else + FR ? dq.pop_back() : dq.pop_front(); + } + /* Break */ + if (error) break; + } + + /* Output */ + if (error) { + cout << "error" << '\n'; + } else { + cout << '['; + while (!dq.empty()) { + if (!FR) { + cout << dq.front(); + dq.pop_front(); + } else { + cout << dq.back(); + dq.pop_back(); + } + + if (!dq.empty()) cout << ','; + } + cout << ']' << '\n'; + } + } + + /* Return */ + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/5430[DS].cpp b/baekjoon/Src/Baekjoon/Solved/5430[DS].cpp new file mode 100644 index 0000000..ed537fa --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/5430[DS].cpp @@ -0,0 +1,92 @@ +#include +#include +#include +#include +using namespace std; + +int main(int argc, char* argv[]) { + /* Faster */ + ios::sync_with_stdio(0); + cin.tie(0); + cout.tie(0); + + /* Input */ + int t; + cin >> t; + for (int i = 0; i < t; i++) { + /* Init */ + deque dq; + + /* Input */ + string p; + cin >> p; + int n; + cin >> n; + + /* Parsing */ + string pars; + cin >> pars; + char num[3]; + int idx = 0; //'', ', ', ', , ' ڸ . + + for (auto c : pars) { + /* '0' ~ '9' */ + if ('0' <= c && c <= '9') num[idx++] = c; + + /* ',' & ']' */ + else if (c == ',' || c == ']') { + int sum = 0; + for (int j = 0; idx != 0; j++) + sum += (num[j] - '0') * (int)pow(10, (idx--) - 1); + if (sum != 0) dq.push_back(sum); + } + } + + /* Function */ + bool error = false; + bool FR = false; // false = Front & true = Rear + + for (auto c : p) { + /* 'R' */ + if (c == 'R') { + FR = !FR; + } + /* 'D' */ + else if (c == 'D') { + if (dq.empty()) + error = true; + else + FR ? dq.pop_back() : dq.pop_front(); + } + /* Break */ + if (error) break; + } + + /* Output */ + if (error) { + cout << "error" << '\n'; + } else { + cout << '['; + while (!dq.empty()) { + if (!FR) { + cout << dq.front(); + dq.pop_front(); + } else { + cout << dq.back(); + dq.pop_back(); + } + + if (!dq.empty()) cout << ','; + } + cout << ']' << '\n'; + } + } + + /* Return */ + return 0; +} + +/* +[Parsing Logic ] +https://se-jung-h.tistory.com/entry/BOJC-%EB%B0%B1%EC%A4%80-5430-AC +*/ diff --git a/baekjoon/Src/Baekjoon/Solved/5585[GR].cpp b/baekjoon/Src/Baekjoon/Solved/5585[GR].cpp new file mode 100644 index 0000000..a360389 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/5585[GR].cpp @@ -0,0 +1,27 @@ +#pragma warning(disable : 4996) +#include + +int main(int argc, char* argv[]) { + /* Init */ + int changes_typ[6] = {500, 100, 50, 10, 5, 1}; + int changes_num = 0; // changes ܵ . + int n; + scanf("%d", &n); + n = 1000 - n; // n ܵ. + + /* Calculate */ + for (int i = 0; i < 6; i++) { + changes_num += n / changes_typ[i]; + n %= changes_typ[i]; + } + + /* Ouptput */ + printf("%d", changes_num); + + /* End */ + return 0; +} + +/* +̿ Ǯ . +*/ diff --git a/baekjoon/Src/Baekjoon/Solved/5597.cpp b/baekjoon/Src/Baekjoon/Solved/5597.cpp new file mode 100644 index 0000000..70ed0b3 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/5597.cpp @@ -0,0 +1,19 @@ +#pragma warning(disable : 4996) +#include +#include + +int main(int argc, char* argv[]) { + bool flag[31] = {}; // 0=false로 초기화 + + for (int i = 0; i < 28; i++) { + int tmp; + scanf("%d", &tmp); + flag[tmp] = true; + } + + for (int i = 1; i <= 30; i++) + if (flag[i] == false) + printf("%d\n", i); + + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/5622.cpp b/baekjoon/Src/Baekjoon/Solved/5622.cpp new file mode 100644 index 0000000..e69de29 diff --git a/baekjoon/Src/Baekjoon/Solved/5639[Graph DC].cpp b/baekjoon/Src/Baekjoon/Solved/5639[Graph DC].cpp new file mode 100644 index 0000000..c648bce --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/5639[Graph DC].cpp @@ -0,0 +1,46 @@ +#include +#include +using namespace std; + +vector node; + +void DC(int l, int r) { + /* Init */ + int i; + for (i = l + 1; i <= r; i++) + if (node[i] > node[l]) break; + + /* Base Case */ + if (l > r) return; + + /* Inductive Step */ + DC(l + 1, i - 1); + DC(i, r); + cout << node[l] << '\n'; +} + +int main(int argc, char* argv[]) { + /* Faster */ + ios::sync_with_stdio(0); + cin.tie(0); + cout.tie(0); + + /* Input */ + while (true) { + int x; + if (!(cin >> x)) break; + node.push_back(x); + } + + /* Divide & Conquer */ + DC(0, node.size() - 1); + + /* Return */ + return 0; +} + +/* +https://www.acmicpc.net/board/view/103352 +https://ongveloper.tistory.com/295 +https://rujang.tistory.com/entry/%EB%B0%B1%EC%A4%80-5639%EB%B2%88-%EC%9D%B4%EC%A7%84-%EA%B2%80%EC%83%89-%ED%8A%B8%EB%A6%AC +*/ diff --git a/baekjoon/Src/Baekjoon/Solved/7287.cpp b/baekjoon/Src/Baekjoon/Solved/7287.cpp new file mode 100644 index 0000000..e5856ae --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/7287.cpp @@ -0,0 +1,6 @@ +#include + +int main(void) { + printf("25\nrpfos"); + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/7568.cpp b/baekjoon/Src/Baekjoon/Solved/7568.cpp new file mode 100644 index 0000000..26485b3 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/7568.cpp @@ -0,0 +1,30 @@ +#pragma warning(disable : 4996) +#include +#include + +typedef struct { + int w; + int h; + int rank; +} PERSON; + +int main(void) { + int w, h = 0; + int n = 0; + + scanf("%d", &n); + PERSON *p = (PERSON *)calloc(n, sizeof(PERSON)); + + for (int i = 0; i < n; i++) { + scanf("%d %d", &p[i].w, &p[i].h); + p[i].rank = 1; + } + + for (int i = 0; i < n; i++) + for (int j = 0; j < n; j++) + if (p[i].w < p[j].w && p[i].h < p[j].h) p[i].rank++; + + for (int i = 0; i < n; i++) printf("%d ", p[i].rank); + + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/7569[Graph].cpp b/baekjoon/Src/Baekjoon/Solved/7569[Graph].cpp new file mode 100644 index 0000000..99ab0b1 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/7569[Graph].cpp @@ -0,0 +1,70 @@ +#include +#include +#include +#include +#include +using namespace std; + +int main(int argc, char* argv[]) { + /* Faster */ + ios::sync_with_stdio(0); + cin.tie(0); + cout.tie(0); + + /* Init */ + int m, n, h; + cin >> m >> n >> h; + int zero = m * n * h, days = 0; + + int x[6] = {-1, 1, 0, 0, 0, 0}; + int y[6] = {0, 0, -1, 1, 0, 0}; + int z[6] = {0, 0, 0, 0, -1, 1}; + + vector>> tomato(h, vector>(n, vector(m))); + queue> q; // row, col, hei + + /* Input */ + for (int hei = 0; hei < h; hei++) + for (int row = 0; row < n; row++) + for (int col = 0; col < m; col++) { + cin >> tomato[hei][row][col]; + if (tomato[hei][row][col] != 0) zero--; + if (tomato[hei][row][col] == 1) q.push(make_tuple(hei, row, col)); + } + + /* BFS */ + while (!q.empty()) { + if (zero == 0) break; + + for (int rept = (int)q.size(); rept > 0; rept--) { + int hei, row, col; + tie(hei, row, col) = q.front(); + q.pop(); + + for (int i = 0; i < 6; i++) { + int nhei = hei + z[i]; // + int nrow = row + y[i]; // + int ncol = col + x[i]; // + + if ((0 <= nhei && nhei <= h - 1) && (0 <= nrow && nrow <= n - 1) && + (0 <= ncol && ncol <= m - 1)) + if (tomato[nhei][nrow][ncol] == 0) { + q.push(make_tuple(nhei, nrow, ncol)); + tomato[nhei][nrow][ncol] = 1; + zero--; + } + } + } + + days++; + } + + /* Output */ + if (zero) + cout << -1; + else + cout << days; + + /* Return */ + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/7576[Graph].cpp b/baekjoon/Src/Baekjoon/Solved/7576[Graph].cpp new file mode 100644 index 0000000..d36deb3 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/7576[Graph].cpp @@ -0,0 +1,74 @@ +#include +#include +#include +#include +using namespace std; + +int main(int argc, char* argv[]) { + /* Faster */ + ios::sync_with_stdio(0); + cin.tie(0); + cout.tie(0); + + /* Init */ + int m, n; + cin >> m >> n; + int zero = m * n, days = 0; + + vector> idx = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}}; // ¿ + + vector> tomato(n, vector(m)); + queue> q; // row, col + + /* Input */ + for (int row = 0; row < n; row++) + for (int col = 0; col < m; col++) { + cin >> tomato[row][col]; + if (tomato[row][col] != 0) zero--; + if (tomato[row][col] == 1) q.push(make_pair(row, col)); + } + + /* BFS */ + while (!q.empty()) { + if (zero == 0) break; + + for (int rept = q.size(); rept > 0; rept--) { + int row = q.front().first; + int col = q.front().second; + q.pop(); + + for (int i = 0; i < 4; i++) { + int nrow = row + idx[i].first; + int ncol = col + idx[i].second; + + if ((0 <= nrow && nrow <= n - 1) && (0 <= ncol && ncol <= m - 1)) + if (tomato[nrow][ncol] == 0) { + q.push(make_pair(nrow, ncol)); + tomato[nrow][ncol] = 1; + zero--; + } + } + } + + days++; + } + + /* Output */ + if (zero) + cout << -1; + else + cout << days; + + /* Return */ + return 0; +} + +/* Debug */ +// cout << '\n'; +// cout << '[' << days << "]\n"; +// for (auto i : tomato) { +// for (auto j : i) +// cout << j << ' '; +// cout << '\n'; +// } +// cout << '\n'; diff --git a/baekjoon/Src/Baekjoon/Solved/7662[DS].cpp b/baekjoon/Src/Baekjoon/Solved/7662[DS].cpp new file mode 100644 index 0000000..3870394 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/7662[DS].cpp @@ -0,0 +1,79 @@ +#include +#include +using namespace std; + +class double_priority_queue { + private: + multiset ms; + + public: + /* Constructor & Destructor */ + double_priority_queue() {} + ~double_priority_queue() {} + + /* Method */ + void insert(int x) { ms.insert(x); } + int top_max() { return *(--ms.end()); } + int top_min() { return *ms.begin(); } + void pop_max() { ms.erase(--ms.end()); } + void pop_min() { ms.erase(ms.begin()); } + bool empty() { return ms.empty(); } +}; + +int main(int argc, char* argv[]) { + /* Faster */ + ios::sync_with_stdio(0); + cin.tie(0); + cout.tie(0); + + /* Input */ + int t; + cin >> t; + while (t--) { + /* Init */ + double_priority_queue dpq; + + /* Input */ + int k; + cin >> k; + while (k--) { + /* Input */ + char c; + cin >> c; + + /* I */ + if (c == 'I') { + int x; + cin >> x; + dpq.insert(x); + } + + /* D */ + else if (c == 'D') { + int x; + cin >> x; + + if (dpq.empty()) continue; + + if (x == 1) + dpq.pop_max(); + else if (x == -1) + dpq.pop_min(); + } + } + + /* Output */ + if (dpq.empty()) + cout << "EMPTY\n"; + else + cout << dpq.top_max() << ' ' << dpq.top_min() << '\n'; + } + + /* Return */ + return 0; +} + +/* +ۿ ٸ Ǯ ѹ ãƺ. +https://donggoolosori.github.io/2020/09/24/boj-7662/ +*/ diff --git a/baekjoon/Src/Baekjoon/Solved/7785[mapset].cpp b/baekjoon/Src/Baekjoon/Solved/7785[mapset].cpp new file mode 100644 index 0000000..6952fc2 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/7785[mapset].cpp @@ -0,0 +1,32 @@ +#include +#include +#include +using namespace std; + +int main(int argc, char* argv[]) { + /* Faster */ + ios::sync_with_stdio(0); + cin.tie(0); + cout.tie(0); + + /* Init */ + set> s; + + /* Input */ + int n; + cin >> n; + while (n--) { + string name, el; + cin >> name >> el; + if (el == "enter") + s.insert(name); + else if (el == "leave") + s.erase(s.find(name)); + } + + /* Output */ + for (auto it : s) cout << it << '\n'; + + /* Return */ + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/8393.cpp b/baekjoon/Src/Baekjoon/Solved/8393.cpp new file mode 100644 index 0000000..09257d1 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/8393.cpp @@ -0,0 +1,18 @@ +#include + +int Sigma_from_one(int num); + +int main(void) { + int num; + + scanf("%d", &num); + + printf("%d", Sigma_from_one(num)); + return 0; +} + +int Sigma_from_one(int num) { + if (num == 1) + return 1; + return num + Sigma_from_one(num - 1); +} diff --git a/baekjoon/Src/Baekjoon/Solved/8958.cpp b/baekjoon/Src/Baekjoon/Solved/8958.cpp new file mode 100644 index 0000000..a855281 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/8958.cpp @@ -0,0 +1,23 @@ +#include + +int main(void) { + char OX[100] = {0}; + int num = 0, result = 0, Count; + + scanf("%d", &Count); + + for (int j = 0; j < Count; j++) { + scanf("%s", OX); // 배열에 문자 들어감. + + for (int i = 0; OX[i] != '\0'; i++) { + if (OX[i] == 'O') // 배열에 들어있는 문자가 'O' 인경우 + num++; + else // 배열에 들어있는 문자가 'X' 인경우 + num = 0; + result += num; + } + printf("%d\n", result); + num = 0, result = 0; + } + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/9012[DS].cpp b/baekjoon/Src/Baekjoon/Solved/9012[DS].cpp new file mode 100644 index 0000000..d4ea69e --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/9012[DS].cpp @@ -0,0 +1,63 @@ +#include +#include +#include +using namespace std; + +int main(int argc, char* argv[]) { + /* Faster */ + ios::sync_with_stdio(0); + cin.tie(0); + cout.tie(0); + + /* Input */ + int T; + cin >> T; + + /* Calculate */ + for (int i = 0; i < T; i++) { + /* Init */ + string str; + cin >> str; + stack s; + bool isno = false; // flag + + /* Calculate */ + for (int i = 0; i < str.size(); i++) { + if (str[i] == '(') { + s.push(true); + } else if (str[i] == ')') { + if (s.empty()) { + isno = true; + break; + } else { + s.pop(); + } + } + } + + /* Output */ + if (!s.empty() || isno == true) + cout << "NO" << '\n'; + else + cout << "YES" << '\n'; + } + + /* End */ + return 0; +} + +/* +'\n' "\n" ӵ . + + ڷᱸ : stack +Ǯ +1. '(' + stack push +2. ')' + stack ʴٸ pop + stack ִٸ "NO" +3. Է ڿ Ȯ ģ + stack ִ "YES" + stack "NO" + +*/ diff --git a/baekjoon/Src/Baekjoon/Solved/9084=3067[DP]_BU_2293.cpp b/baekjoon/Src/Baekjoon/Solved/9084=3067[DP]_BU_2293.cpp new file mode 100644 index 0000000..6454495 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/9084=3067[DP]_BU_2293.cpp @@ -0,0 +1,28 @@ +#pragma warning(disable : 4996) +#include + +int main(int argc, char* argv[]) { + int T; + scanf("%d", &T); + for (int i = 0; i < T; i++) { + /* Init */ + int C[10001] = {1}; + int V[20] = {}; + + /* Input */ + int N; + scanf("%d", &N); + for (int j = 0; j < N; j++) scanf("%d", &V[j]); + int M; + scanf("%d", &M); + + /* DP */ + for (int i = 0; i < N; i++) + for (int j = 0; j <= M; j++) C[j] += (j >= V[i] ? C[j - V[i]] : 0); + + /* Output */ + printf("%d\n", C[M]); + } + + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/9095[DP]_BU.cpp b/baekjoon/Src/Baekjoon/Solved/9095[DP]_BU.cpp new file mode 100644 index 0000000..2b1654f --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/9095[DP]_BU.cpp @@ -0,0 +1,36 @@ +#pragma warning(disable : 4996) +#include + +int cache[11] = {0, 1, 2, 4}; + +int main(int argc, char* argv[]) { + /* Input */ + int T; + scanf("%d", &T); + + /* Calculate */ + for (int i = 0; i < T; i++) { + /* Input */ + int n; + scanf("%d", &n); + + /* Calculate */ + for (int i = 4; i <= n; i++) + cache[i] = cache[i - 1] + cache[i - 2] + cache[i - 3]; + + /* Output */ + printf("%d\n", cache[n]); + } + + /* End */ + return 0; +} + +/* ٸ . ؼ ٽ Ǯ + * . */ +/* Bottom Up ǰ */ + +/* +1, 2, 3 ϱ Ʈ 9 ִ. +ѹ ؼ ø. +*/ diff --git a/baekjoon/Src/Baekjoon/Solved/9498.cpp b/baekjoon/Src/Baekjoon/Solved/9498.cpp new file mode 100644 index 0000000..31b05b1 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/9498.cpp @@ -0,0 +1,20 @@ +#pragma warning(disable : 4996) +#include + +int main(int argc, char* argv[]) { + int n; + scanf("%d", &n); + + if (90 <= n && n <= 100) + printf("A"); + else if (80 <= n && n < 90) + printf("B"); + else if (70 <= n && n < 80) + printf("C"); + else if (60 <= n && n < 70) + printf("D"); + else + printf("F"); + + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/9507[DP]_TD.cpp b/baekjoon/Src/Baekjoon/Solved/9507[DP]_TD.cpp new file mode 100644 index 0000000..853b0ff --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/9507[DP]_TD.cpp @@ -0,0 +1,34 @@ +#pragma warning(disable : 4996) +#include + +long long C[68] = {}; + +long long koong(int n) { + /* Base Case */ + if (n < 2) + return 1; + else if (n == 2) + return 2; + else if (n == 3) + return 4; + /* Memoization */ + else if (C[n] != 0) + return C[n]; + /* Inductive Step */ + else + return C[n] = koong(n - 1) + koong(n - 2) + koong(n - 3) + koong(n - 4); +} + +int main(int argc, char* argv[]) { + int t; + scanf("%d", &t); + for (int i = 0; i < t; i++) { + int n; + scanf("%d", &n); + printf("%lld\n", koong(n)); + } + + return 0; +} + +/* long long 900 ǥ ִ. */ diff --git a/baekjoon/Src/Baekjoon/Solved/9625[DP]_BU.cpp b/baekjoon/Src/Baekjoon/Solved/9625[DP]_BU.cpp new file mode 100644 index 0000000..58d5996 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/9625[DP]_BU.cpp @@ -0,0 +1,30 @@ +#pragma warning(disable : 4996) +#include + +int main(int argc, char* argv[]) { + /* Input */ + int K; + scanf("%d", &K); + + /* DP */ + int DP[2][46] = {1}; + + for (int i = 1; i <= K; i++) { + DP[0][i] = DP[1][i - 1]; + DP[1][i] = DP[1][i - 1] + DP[0][i - 1]; + } + + printf("%d %d", DP[0][K], DP[1][K]); + + return 0; +} + +/* + 0 1 2 3 4 5 6 7 8 +A 1 0 1 1 2 +B 0 1 1 2 3 + + A B +A = -A +A +B = +B 0 +*/ diff --git a/baekjoon/Src/Baekjoon/Solved/9655[DP]_XX BU.cpp b/baekjoon/Src/Baekjoon/Solved/9655[DP]_XX BU.cpp new file mode 100644 index 0000000..b625466 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/9655[DP]_XX BU.cpp @@ -0,0 +1,10 @@ +#pragma warning(disable : 4996) +#include + +int main(int argc, char* argv[]) { + int N; + scanf("%d", &N); + printf("%s", N % 2 == 0 ? "CY" : "SK"); + + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/9656[DP].cpp b/baekjoon/Src/Baekjoon/Solved/9656[DP].cpp new file mode 100644 index 0000000..1c6b564 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/9656[DP].cpp @@ -0,0 +1,10 @@ +#pragma warning(disable : 4996) +#include + +int main(int argc, char* argv[]) { + int N; + scanf("%d", &N); + printf("%s", N % 2 == 0 ? "SK" : "CY"); + + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/9657[DP]_BU.cpp b/baekjoon/Src/Baekjoon/Solved/9657[DP]_BU.cpp new file mode 100644 index 0000000..51803d0 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/9657[DP]_BU.cpp @@ -0,0 +1,20 @@ +#pragma warning(disable : 4996) +#include +#include + +int main(int argc, char* argv[]) { + /* Input */ + int N; + scanf("%d", &N); + + /* DP */ + bool F[1001] = {0, 1, 0, 1, 1}; + for (int i = 5; i <= N; i++) + F[i] = !(F[i - 1] && F[i - 3] && F[i - 4]); + + /* Output */ + printf("%s", F[N] == 1 ? "SK" : "CY"); + + /* End */ + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/9658[DP]_BU.cpp b/baekjoon/Src/Baekjoon/Solved/9658[DP]_BU.cpp new file mode 100644 index 0000000..e7b25c3 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/9658[DP]_BU.cpp @@ -0,0 +1,20 @@ +#pragma warning(disable : 4996) +#include +#include + +int main(int argc, char* argv[]) { + /* Input */ + int N; + scanf("%d", &N); + + /* DP */ + bool F[1001] = {1, 0, 1, 0, 1}; + for (int i = 5; i <= N; i++) + F[i] = !(F[i - 1] && F[i - 3] && F[i - 4]); + + /* Output */ + printf("%s", F[N] == 1 ? "SK" : "CY"); + + /* End */ + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/9659[not DP].cpp b/baekjoon/Src/Baekjoon/Solved/9659[not DP].cpp new file mode 100644 index 0000000..325ecf7 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/9659[not DP].cpp @@ -0,0 +1,10 @@ +#pragma warning(disable : 4996) +#include + +int main(int argc, char* argv[]) { + long long N; + scanf("%lld", &N); + printf("%s", N % 2 == 0 ? "CY" : "SK"); + + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/9660[DP]_XX.cpp b/baekjoon/Src/Baekjoon/Solved/9660[DP]_XX.cpp new file mode 100644 index 0000000..bb8b0a0 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/9660[DP]_XX.cpp @@ -0,0 +1,12 @@ +#pragma warning(disable : 4996) +#include +#include + +int main(int argc, char* argv[]) { + long long N; + scanf("%lld", &N); + + printf("%s", (N % 7 == 0 || N % 7 == 2) ? "CY" : "SK"); + + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/9661[not dp].cpp b/baekjoon/Src/Baekjoon/Solved/9661[not dp].cpp new file mode 100644 index 0000000..723191e --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/9661[not dp].cpp @@ -0,0 +1,12 @@ +#pragma warning(disable : 4996) +#include +#include + +int main(int argc, char* argv[]) { + long long N; + scanf("%lld", &N); + + printf("%s", (N % 5 == 0 || N % 5 == 2) ? "CY" : "SK"); + + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/9662[DP].cpp b/baekjoon/Src/Baekjoon/Solved/9662[DP].cpp new file mode 100644 index 0000000..40e2b79 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/9662[DP].cpp @@ -0,0 +1,115 @@ +#pragma warning(disable : 4996) +#include +#include +#include + +#define MAX(a, b) (((a) > (b)) ? (a) : (b)) + +#define MAX_LEN 10000 +#define MAXCYCLE_LEN 536 +#define SP (MAX_LEN / 2) +/* +MAXLEN : Ŭ ǺDZ ִ ̸ . +MAXCYCLE : 1000, 2000 ƿ ū Ŭ ִ ̷ ص . +SP : Search Point = Ŭ Ž . +*/ + +bool F[MAX_LEN] = {}; + +int main(int argc, char* argv[]) { + /* Input */ + int M; + scanf("%d", &M); + int K; + scanf("%d", &K); + + int* A = (int*)calloc(K, sizeof(int)); + for (int i = 0; i < K; i++) + scanf("%d", &A[i]); + + /* Calculate (Fill F[MAXLEN]) */ + /* Init */ + F[0] = 0; + for (int i = 0; i < K; i++) + F[A[i]] = 1; + + /* Fill F[MAXLEN] */ + for (int i = 1; i < MAX_LEN; i++) { // MAXLEN . + if (F[i] == 1) + continue; + + int tmp = 1; + for (int j = 0; j < K; j++) + tmp = tmp && (i - A[j] >= 0 ? F[i - A[j]] : 1); + F[i] = !tmp; + } + + ///* debug */ + // printf("\n"); + // printf("val : "); + // for (int i = 0; i < MAXCYCLE_LEN; i++) + // printf("%2d ", F[i]); + // printf("\n"); + + /* Output */ + /* Case 1 : M < MAXLEN */ + if (M < MAX_LEN) { + // Init + int ans = 0; + + // i <= M + for (int i = 1; i <= M; i++) + if (F[i] == 0) + ans++; + + // Output + printf("%d", ans); + } + + /* Case 2 : MAXLEN <= M */ + else { + /* Init */ + int maxcycle_len = 0; // cycle ֱⰡ n̶, MAXCYCLE_LEN n . + + /* Find Cycle */ + for (int cycle_len = 1; cycle_len <= MAXCYCLE_LEN; cycle_len++) { // cycle_len cycle ̴. + /* Comparison */ + for (int i = 0; i < cycle_len; i++) { // cycle_len ̸ŭ ݺ. + /* cycle : X */ + if (F[(SP + i)] != F[SP + cycle_len + i]) + break; + /* cycle : O */ + if (i == cycle_len - 1) + maxcycle_len = MAX(maxcycle_len, cycle_len); + } + } + + ///* debug */ + // printf("maxcycle_len : %d\n\n", maxcycle_len); + + /* Zero Caculate */ + // Init + int ans = 0; + + // M < SP(5000) + for (int i = 1; i < SP; i++) + if (F[i] == 0) ans++; + + // SP(5000) < M : zero count + int count_zero = 0; + for (int i = SP; i < SP + maxcycle_len; i++) + if (F[i] == 0) count_zero++; + ans += ((M - SP) / maxcycle_len) * count_zero; + + // Remainder + for (int i = SP; i <= SP + ((M - SP) % maxcycle_len); i++) + if (F[i] == 0) ans++; + + // Output + printf("%d", ans); + } + + /* End */ + free(A); + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Solved/9711[DP]_BU.cpp b/baekjoon/Src/Baekjoon/Solved/9711[DP]_BU.cpp new file mode 100644 index 0000000..d777f96 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Solved/9711[DP]_BU.cpp @@ -0,0 +1,33 @@ +#pragma warning(disable : 4996) +#include + +long C[10001] = {0, 1}; + +int fibonacci(int P, int Q) { + if (Q == 1) // Q 1϶ .... ̰ ϸ 100% + return 0; + + for (int i = 2; i <= P; i++) + C[i] = (C[i - 2] + C[i - 1]) % Q; + + return C[P]; +} +/* +C[i] = ((C[i - 1] % Q) + (C[i - 2] % Q)) % Q; + ϸ ðʰ . Ƚ ٿ Ѵ. + + κ . (˰ ڿ ǿ .) +*/ + +int main(int argc, char* argv[]) { + int T; + scanf("%d", &T); + + for (int i = 0; i < T; i++) { + int P, Q; + scanf("%d %d", &P, &Q); + printf("Case #%d: %d\n", i + 1, fibonacci(P, Q)); + } + + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Unsolved/16236[Graph].cpp b/baekjoon/Src/Baekjoon/Unsolved/16236[Graph].cpp new file mode 100644 index 0000000..fb99b1e --- /dev/null +++ b/baekjoon/Src/Baekjoon/Unsolved/16236[Graph].cpp @@ -0,0 +1,17 @@ +#include +#include +using namespace std; + +int main(int argc, char* argv[]) { + /* Faster */ + ios::sync_with_stdio(0); + cin.tie(0); + cout.tie(0); + + /* Init */ + + /* Input */ + + /* Return */ + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Unsolved/17298.cpp b/baekjoon/Src/Baekjoon/Unsolved/17298.cpp new file mode 100644 index 0000000..9e7ec37 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Unsolved/17298.cpp @@ -0,0 +1,18 @@ +#include +#include +using namespace std; + +int main(int argc, char* argv[]) { + /* Faster */ + ios::sync_with_stdio(0); + cin.tie(0); + cout.tie(0); + + /* Init */ + + /* End */ + return 0; +} + +/* for ̿ , ð⵵ O(n^2), ðʰ + * ߻ϰ ȴ. */ diff --git a/baekjoon/Src/Baekjoon/Unsolved/1838.cpp b/baekjoon/Src/Baekjoon/Unsolved/1838.cpp new file mode 100644 index 0000000..5599dd2 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Unsolved/1838.cpp @@ -0,0 +1,35 @@ +#pragma warning(disable : 4996) +#include +#include +#include + +void optimized_bubble_sort(int A[], int n) { + bool flag; + + for (int i = n - 1; i >= 1; i--) { + flag = false; + for (int j = 0; j <= i - 1; j++) { + if (A[j] > A[j + 1]) { + int tmp = A[j]; + A[j] = A[j + 1]; + A[j + 1] = tmp; + flag = true; + } + } + if (flag == false) return; + } +} + +int main(void) { + int n = 3; + // scanf("%d", &n); + + int* A = (int*)calloc(n, sizeof(int)); + for (int i = 0; i < n; i++) scanf("%d", &A[i]); + + optimized_bubble_sort(A, n); + + for (int i = 0; i < n; i++) printf("%d ", A[i]); + + return 0; +} diff --git a/baekjoon/Src/Baekjoon/Unsolved/2893[DP]_BU.cpp b/baekjoon/Src/Baekjoon/Unsolved/2893[DP]_BU.cpp new file mode 100644 index 0000000..af65a9d --- /dev/null +++ b/baekjoon/Src/Baekjoon/Unsolved/2893[DP]_BU.cpp @@ -0,0 +1,41 @@ +#pragma warning(disable : 4996) +#include +#include + +#define min(a, b) (((a) < (b)) ? (a) : (b)) + +int C[5001] = {}; +int V[2] = {3, 5}; + +int main(int argc, char* argv[]) { + /* Input */ + int n; + scanf("%d", &n); + + /* DP */ + // init + for (int i = 1; i <= n; i++) C[i] = SHRT_MAX; + // DP + for (int i = 0; i <= 1; i++) + for (int j = 1; j <= n; j++) + C[j] = min(((j - V[i]) >= 0 ? (C[j - V[i]] + 1) : SHRT_MAX), C[j]); + + /* Output */ + printf("%d", C[n] == SHRT_MAX ? -1 : C[n]); + + /* End */ + return 0; +} + +/* +INT_MAX ü ״ , C[j - V[i]] + 1 INT_MAX + 1 +߻Ͽ ÷ο찡 ߻Ѵ. , ̻ϰ µǹǷ +SHRT_MAX Ѵ ־. +( ġ ּڰ 1̰, k ִ 10000̹Ƿ, + ִ ִ 10000 ̴. SHRT_MAX ص +.) +*/ + +/* +2294 2 logic Ǭ. +*/ diff --git a/baekjoon/Src/Baekjoon/Unsolved/MacroFunctions.h b/baekjoon/Src/Baekjoon/Unsolved/MacroFunctions.h new file mode 100644 index 0000000..e0826d0 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Unsolved/MacroFunctions.h @@ -0,0 +1,18 @@ +#ifndef __MACROFUNC_H__ +#define __MACROFUNC_H__ + +#define SWAP(a, b, type) \ + do { \ + type temp = a; \ + a = b; \ + b = temp; \ + } while (0) + +#define MIN_2(a, b) (((a) < (b)) ? (a) : (b)) +#define MIN_3(a, b, c) \ + (((a) < (b)) ? ((a) < (c) ? (a) : (c)) : ((b) < (c) ? (b) : (c))) +#define MAX_2(a, b) (((a) > (b)) ? (a) : (b)) +#define MAX_3(a, b, c) \ + (((a) > (b)) ? ((a) > (c) ? (a) : (c)) : ((b) > (c) ? (b) : (c))) + +#endif diff --git a/baekjoon/Src/Baekjoon/Unsolved/SortingAlgorithms.h b/baekjoon/Src/Baekjoon/Unsolved/SortingAlgorithms.h new file mode 100644 index 0000000..047f5a9 --- /dev/null +++ b/baekjoon/Src/Baekjoon/Unsolved/SortingAlgorithms.h @@ -0,0 +1,101 @@ +#ifndef __SORT_C_H__ +#define __SORT_C_H__ + +#include +#include + +static void merge_merge(int A[], int left, int middle, int right) { + int i = left; + int j = middle + 1; + int t = 0; + int* temp = (int*)calloc(right - left + 1, sizeof(int)); + + while (i <= middle && j <= right) { + if (A[i] <= A[j]) + temp[t++] = A[i++]; + else + temp[t++] = A[j++]; + } + + while (i <= middle) temp[t++] = A[i++]; + while (j <= right) temp[t++] = A[j++]; + + i = left, t = 0; + while (i <= right) A[i++] = temp[t++]; + + free(temp); +} + +void merge_sort(int A[], int left, int right) { + if (left < right) { + int middle = (left + right) / 2; + merge_sort(A, left, middle); + merge_sort(A, middle + 1, right); + merge_merge(A, left, middle, right); + } +} + +int quick_partition(int A[], int left, int right) { + int pivot = A[right]; + int i = left - 1; + + for (int j = left; j <= right - 1; j++) { + if (A[j] <= pivot) { + i += 1; + int temp = A[i]; + A[i] = A[j]; + A[j] = temp; + } + } + int temp = A[i + 1]; + A[i + 1] = A[right]; + A[right] = temp; + + return i + 1; +} + +void quick_sort(int A[], int left, int right) { + if (left < right) { + int p = quick_partition(A, left, right); + quick_sort(A, left, p - 1); + quick_sort(A, p + 1, right); + } +} + +void down_heap(int A[], int i, int n) { + int left = 2 * i + 1; + int right = 2 * i + 2; + int largest = i; + int temp = 0; + + if (left < n) { + if (A[left] > A[largest]) largest = left; + } + if (right < n) { + if (A[right] > A[largest]) largest = right; + } + if (largest != i) { + temp = A[i]; + A[i] = A[largest]; + A[largest] = temp; + down_heap(A, largest, n); + } +} + +void heap_sort(int A[], int n) { + for (int i = (n - 1) / 2; i >= 0; i--) down_heap(A, i, n); + + for (int i = n - 1; i >= 1; i--) { + int temp = A[0]; + A[0] = A[i]; + A[i] = temp; + down_heap(A, 0, i); + } +} + +void print_sort(int arr[], int n) { + for (int i = 0; i < n; i++) printf("%d ", arr[i]); + printf("\n"); +} + +#endif diff --git a/baekjoon/VScode.code-workspace b/baekjoon/VScode.code-workspace new file mode 100644 index 0000000..6c83502 --- /dev/null +++ b/baekjoon/VScode.code-workspace @@ -0,0 +1,14 @@ +{ + "folders": [ + { + "path": "." + } + ], + "settings": { + "files.associations": { + "iostream": "cpp", + "queue": "cpp", + "cstdio": "cpp" + } + } +} \ No newline at end of file