From e162486df177ca9aa5f8bd5c95a1b2fe2bb98923 Mon Sep 17 00:00:00 2001 From: e2hang <2099307493@qq.com> Date: Sun, 31 Aug 2025 10:21:06 +0800 Subject: [PATCH] Altered Structure --- Algorithm/{ => DS-Related}/Graph/BFS/Maze.cpp | 0 .../DFS/UVa1600Knight-Move betteruseBSF.cpp | 32 +++++++++++++++++++ .../Graph/DFS/UVa572-Oil-Deposits.cpp | 0 .../EulerGraph/UVa-10129-PlayOnWords.cpp | 0 ...„้”ฎ็›˜ Broken Keyboard (a.k.a. Beiju Text).cpp | 0 .../Divide&Conquer/UVa536-TreeRecovery.cpp | 21 ++++++++++++ 6 files changed, 53 insertions(+) rename Algorithm/{ => DS-Related}/Graph/BFS/Maze.cpp (100%) create mode 100644 Algorithm/DS-Related/Graph/DFS/UVa1600Knight-Move betteruseBSF.cpp rename Algorithm/{ => DS-Related}/Graph/DFS/UVa572-Oil-Deposits.cpp (100%) rename Algorithm/{ => DS-Related}/Graph/EulerGraph/UVa-10129-PlayOnWords.cpp (100%) rename Algorithm/{ => DS-Related}/List/UVA11988 ็ ดๆŸ็š„้”ฎ็›˜ Broken Keyboard (a.k.a. Beiju Text).cpp (100%) create mode 100644 Algorithm/Divide&Conquer/UVa536-TreeRecovery.cpp diff --git a/Algorithm/Graph/BFS/Maze.cpp b/Algorithm/DS-Related/Graph/BFS/Maze.cpp similarity index 100% rename from Algorithm/Graph/BFS/Maze.cpp rename to Algorithm/DS-Related/Graph/BFS/Maze.cpp diff --git a/Algorithm/DS-Related/Graph/DFS/UVa1600Knight-Move betteruseBSF.cpp b/Algorithm/DS-Related/Graph/DFS/UVa1600Knight-Move betteruseBSF.cpp new file mode 100644 index 0000000..5206714 --- /dev/null +++ b/Algorithm/DS-Related/Graph/DFS/UVa1600Knight-Move betteruseBSF.cpp @@ -0,0 +1,32 @@ +#include +using namespace std; +//abสวึีตใ +int dx[8] = {-2, -1, 1, 2, 2, 1, -1, -2}; +int dy[8] = {1, 2, 2, 1, -1, -2, -2, -1}; +int step[9][9]; + +void dfs(int _a, int _b, int _n, int _m){ + if(_n > 8 || _n < 1 || _m < 1 || _m > 8) return; + if(_n == _a && _m == _b) return; + for(int i = 0; i < 8; i++){ + int nx = _n + dx[i]; + int ny = _m + dy[i]; + + if (nx >= 1 && nx <= 8 && ny >= 1 && ny <= 8) { + int stepnew = step[_n][_m] + 1; + if (step[nx][ny] == 0 || stepnew < step[nx][ny]) { + step[nx][ny] = stepnew; + dfs(_a, _b, nx, ny); + } + } + } +} + +int main(){ + int a, b, n, m; + cin >> n >> m >> a >> b; + step[n][m] = 0; + dfs(a, b, n, m); + cout << step[a][b] << endl; + return 0; +} diff --git a/Algorithm/Graph/DFS/UVa572-Oil-Deposits.cpp b/Algorithm/DS-Related/Graph/DFS/UVa572-Oil-Deposits.cpp similarity index 100% rename from Algorithm/Graph/DFS/UVa572-Oil-Deposits.cpp rename to Algorithm/DS-Related/Graph/DFS/UVa572-Oil-Deposits.cpp diff --git a/Algorithm/Graph/EulerGraph/UVa-10129-PlayOnWords.cpp b/Algorithm/DS-Related/Graph/EulerGraph/UVa-10129-PlayOnWords.cpp similarity index 100% rename from Algorithm/Graph/EulerGraph/UVa-10129-PlayOnWords.cpp rename to Algorithm/DS-Related/Graph/EulerGraph/UVa-10129-PlayOnWords.cpp diff --git a/Algorithm/List/UVA11988 ็ ดๆŸ็š„้”ฎ็›˜ Broken Keyboard (a.k.a. Beiju Text).cpp b/Algorithm/DS-Related/List/UVA11988 ็ ดๆŸ็š„้”ฎ็›˜ Broken Keyboard (a.k.a. Beiju Text).cpp similarity index 100% rename from Algorithm/List/UVA11988 ็ ดๆŸ็š„้”ฎ็›˜ Broken Keyboard (a.k.a. Beiju Text).cpp rename to Algorithm/DS-Related/List/UVA11988 ็ ดๆŸ็š„้”ฎ็›˜ Broken Keyboard (a.k.a. Beiju Text).cpp diff --git a/Algorithm/Divide&Conquer/UVa536-TreeRecovery.cpp b/Algorithm/Divide&Conquer/UVa536-TreeRecovery.cpp new file mode 100644 index 0000000..5221575 --- /dev/null +++ b/Algorithm/Divide&Conquer/UVa536-TreeRecovery.cpp @@ -0,0 +1,21 @@ +#include +#include +using namespace std; + +void build(string& _pre, string& _in, int pre_front, int pre_end, int in_front, int in_end){ + if (pre_front > pre_end) return; + + char root; + root = _pre[pre_front]; + int k = _in.find(root, in_front);//ดำin_frontฟชสผ + int leftsize = k - in_front; + build(_pre, _in, pre_front + 1, pre_front + leftsize, in_front, k - 1); + build(_pre, _in, pre_front + leftsize + 1 , pre_end, k + 1, in_end); + cout << root << " "; +} +int main(){ + string pre, in; + cin >> pre >> in; + build(pre, in, 0, pre.size() - 1, 0, in.size() - 1); + return 0; +}