diff --git a/.gitignore b/.gitignore
index 8ec8dc9..9280b34 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,5 @@
.venv
+cmake-build-debug
/*.exe
/*.dSYM
diff --git a/.idea/MarsCodeWorkspaceAppSettings.xml b/.idea/MarsCodeWorkspaceAppSettings.xml
index e2a065b..b26fdc6 100644
--- a/.idea/MarsCodeWorkspaceAppSettings.xml
+++ b/.idea/MarsCodeWorkspaceAppSettings.xml
@@ -1,6 +1,7 @@
+
\ No newline at end of file
diff --git a/.idea/editor.xml b/.idea/editor.xml
index 69ae789..8019d75 100644
--- a/.idea/editor.xml
+++ b/.idea/editor.xml
@@ -255,6 +255,7 @@
+
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index fb8cdbd..1a30243 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -20,7 +20,29 @@
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -30,10 +52,14 @@
-
-
-
+
+
+
+
+
+
+
@@ -53,6 +79,7 @@
+
@@ -82,94 +109,214 @@
- {
+ "keyToString": {
+ "ASKED_SHARE_PROJECT_CONFIGURATION_FILES": "true",
+ "C/C++ 文件.D_pojcs101_M02692.cpp.executor": "Run",
+ "C/C++ 文件.luogu_UVA755.cpp.executor": "Run",
+ "C/C++ 文件.luogu_ez_B3628.cpp.executor": "Run",
+ "C/C++ 文件.luogu_model_dsu_P3367.cpp.executor": "Run",
+ "C/C++ 文件.ojcs101_E01003.cpp.executor": "Run",
+ "C/C++ 文件.ojcs101_E01218.cpp.executor": "Run",
+ "C/C++ 文件.ojcs101_E02883.cpp.executor": "Run",
+ "C/C++ 文件.pojcs101_M01017_6_boxes.cpp.executor": "Run",
+ "C/C++ 文件.pojcs101_M01088_ski.cpp.executor": "Run",
+ "C/C++ 文件.pojcs101_M01321_chest_grid.cpp.executor": "Debug",
+ "C/C++ 文件.pojcs101_M01328_radar_greedy.cpp.executor": "Debug",
+ "C/C++ 文件.pojcs101_M01852_ants_falling.cpp.executor": "Run",
+ "C/C++ 文件.pojcs101_M01922_ride_follower.cpp.executor": "Run",
+ "C/C++ 文件.pojcs101_M02039_snakey_encryption.cpp.executor": "Run",
+ "C/C++ 文件.pojcs101_M02431_cows_gas_leak.cpp.executor": "Debug",
+ "C/C++ 文件.pojcs101_M02524_ubiquitous_religions_dsu.cpp.executor": "Run",
+ "C/C++ 文件.pojcs101_M02692.cpp.executor": "Run",
+ "C/C++ 文件.pojcs101_M02692_12_coins.cpp.executor": "Run",
+ "C/C++ 文件.pojcs101_M02694_polish_notation_tree.cpp.executor": "Run",
+ "CMake 应用程序.exercises.executor": "Run",
+ "CMake 应用程序.pojcs101_M02694_polish_notation_tree.executor": "Debug",
+ "CidrDebugProfileConversion": "true",
+ "ModuleVcsDetector.initialDetectionPerformed": "true",
+ "Python.lc_127.executor": "Run",
+ "RunOnceActivity.RadMigrateCodeStyle": "true",
+ "RunOnceActivity.ShowReadmeOnStart": "true",
+ "RunOnceActivity.cidr.known.project.marker": "true",
+ "RunOnceActivity.git.unshallow": "true",
+ "RunOnceActivity.readMode.enableVisualFormatting": "true",
+ "RunOnceActivity.typescript.service.memoryLimit.init": "true",
+ "RunOnceActivity.west.config.association.type.startup.service": "true",
+ "SHARE_PROJECT_CONFIGURATION_FILES": "true",
+ "cf.first.check.clang-format": "false",
+ "cidr.known.project.marker": "true",
+ "codeWithMe.voiceChat.enabledByDefault": "false",
+ "deletionFromPopupRequiresConfirmation": "false",
+ "git-widget-placeholder": "main",
+ "last_opened_file_path": "/Users/roger/coding/exercises",
+ "node.js.detected.package.jshint": "true",
+ "node.js.selected.package.jshint": "",
+ "nodejs_package_manager_path": "npm",
+ "org.rust.first.attach.projects": "true",
+ "settings.editor.selected.configurable": "CPPToolchains"
}
-}]]>
+}
-
-
-
+
+
-
+
-
-
+
-
+
-
-
+
-
+
-
-
+
-
+
-
-
+
-
+
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 0000000..ad9eb41
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,15 @@
+cmake_minimum_required(VERSION 3.10)
+project(exercises)
+
+# 设置 C++ 标准(例如 C++17)
+set(CMAKE_CXX_STANDARD 17)
+
+# 递归查找当前目录下所有的 .cpp 文件
+file(GLOB_RECURSE SOURCES "*.cpp")
+
+# 遍历所有找到的 .cpp 文件,为每个文件单独创建一个可执行目标
+foreach(source ${SOURCES})
+ # 获取文件名(不带扩展名)作为可执行文件的名字
+ get_filename_component(name ${source} NAME_WE)
+ add_executable(${name} ${source})
+endforeach()
\ No newline at end of file
diff --git a/luogu_template_dsu_P3367.cpp b/luogu_template_dsu_P3367.cpp
new file mode 100644
index 0000000..b722fc4
--- /dev/null
+++ b/luogu_template_dsu_P3367.cpp
@@ -0,0 +1,48 @@
+#include
+#include
+
+using namespace std;
+
+class Dsu {
+public:
+ struct Node {
+ size_t parent, size;
+ };
+
+ vector nodes;
+
+ explicit Dsu(const size_t size) : nodes(size) {
+ for (size_t i = 0; i < size; i++) {
+ nodes[i] = {.parent = i, .size = 0};
+ }
+ }
+
+ size_t find(const size_t x) {
+ if (nodes[x].parent == x) { return x; }
+ return nodes[x].parent = find(nodes[x].parent);
+ }
+
+ void unite(size_t x, size_t y) {
+ if ((x = find(x)) == (y = find(y))) { return; }
+ if (nodes[x].size > nodes[y].size) { swap(x, y); }
+ nodes[x].parent = y;
+ nodes[y].size += nodes[x].size;
+ }
+};
+
+int main() {
+ ios::sync_with_stdio(false);
+ cin.tie(nullptr);
+
+ int elements_count, operations_count;
+ cin >> elements_count >> operations_count;
+ Dsu dsu(elements_count);
+ for (int _ = 0; _ < operations_count; _++) {
+ int op, x, y;
+ cin >> op >> x >> y;
+ if (op == 1) { dsu.unite(x, y); }
+ if (op == 2) { cout << (dsu.find(x) == dsu.find(y) ? 'Y' : 'N') << endl; }
+ }
+
+ return 0;
+}
diff --git a/pojcs101_M02524_ubiquitous_religions_dsu.cpp b/pojcs101_M02524_ubiquitous_religions_dsu.cpp
index a4d0339..e3e49fa 100644
--- a/pojcs101_M02524_ubiquitous_religions_dsu.cpp
+++ b/pojcs101_M02524_ubiquitous_religions_dsu.cpp
@@ -34,5 +34,20 @@ int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
+ size_t students_count, pairs_count;
+ for (int case_id = 1; cin >> students_count >> pairs_count && students_count; case_id++) {
+ cout << "Case " << case_id << ": ";
+ Dsu dsu(students_count);
+ size_t x, y, ans = 0;
+ for (int _ = 0; _ < pairs_count; _++) {
+ cin >> x >> y;
+ dsu.unite(x - 1, y - 1);
+ }
+ for (size_t node_id = 0; node_id < students_count; node_id++) {
+ ans += node_id == dsu.find(node_id);
+ }
+ cout << ans << endl;
+ }
+
return 0;
}
diff --git a/pojcs101_M02694_polish_notation_tree.cpp b/pojcs101_M02694_polish_notation_tree.cpp
new file mode 100644
index 0000000..8196fdc
--- /dev/null
+++ b/pojcs101_M02694_polish_notation_tree.cpp
@@ -0,0 +1,97 @@
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+using namespace std;
+
+
+class NotationTree {
+public:
+ using Data = variant;
+
+ struct TreeNode {
+ Data data;
+ optional left_idx, right_idx;
+
+ explicit TreeNode(const string& value) { data = parse_string(value); }
+ explicit TreeNode(const Data value) { data = value; }
+
+ [[nodiscard]] bool is_operator() const {
+ return std::holds_alternative(data);
+ }
+
+ [[nodiscard]] char get_operator() const {
+ if (!is_operator()) { throw invalid_argument("Node is not operator"); }
+ return get(data);
+ }
+
+ [[nodiscard]] double get_number() const {
+ if (is_operator()) { throw invalid_argument("Node is operator"); }
+ return get(data);
+ }
+ };
+
+ static Data parse_string(const string& value) {
+ if (value == "+" || value == "-" || value == "*" || value == "/") {
+ return value[0];
+ }
+ return stod(value);
+ }
+
+ vector nodes;
+
+ tuple build_from_poland(const vector& datas, const size_t start_idx = 0) {
+ size_t this_idx = nodes.size();
+ nodes.emplace_back(datas[start_idx]);
+ if (!nodes.back().is_operator()) { return make_tuple(this_idx, start_idx + 1); }
+ auto [left_idx, right_start_idx] = build_from_poland(datas, start_idx + 1);
+ nodes[this_idx].left_idx = left_idx;
+ auto [right_idx, right_end_idx] = build_from_poland(datas, right_start_idx);
+ nodes[this_idx].right_idx = right_idx;
+ return make_tuple(this_idx, right_end_idx);
+ }
+
+ double calculate(const size_t idx = 0) {
+ if (!nodes[idx].is_operator()) {
+ return nodes[idx].get_number();
+ }
+ if (!nodes[idx].left_idx.has_value() || !nodes[idx].right_idx.has_value()) {
+ throw invalid_argument("Tree is not complete");
+ }
+ const double left_result = calculate(nodes[idx].left_idx.value()),
+ right_result = calculate(nodes[idx].right_idx.value());
+ switch (nodes[idx].get_operator()) {
+ case '+': return left_result + right_result;
+ case '-': return left_result - right_result;
+ case '*': return left_result * right_result;
+ case '/': return left_result / right_result;
+ default: throw invalid_argument("Invalid operator");
+ }
+ }
+};
+
+
+int main() {
+ ios::sync_with_stdio(false);
+ cin.tie(nullptr);
+
+ string poland_notation, token;
+ vector datas;
+ getline(cin, poland_notation);
+ stringstream ss(poland_notation);
+ while (ss >> token) {
+ datas.push_back(NotationTree::parse_string(token));
+ }
+ NotationTree tree;
+ tree.build_from_poland(datas);
+ printf("%f\n", tree.calculate());
+
+ return 0;
+}