diff --git a/.gitignore b/.gitignore index 0c3d9d0..8ec8dc9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ .venv /*.exe +/*.dSYM # 忽略 linux 编译产物 /* diff --git a/.idea/workspace.xml b/.idea/workspace.xml index f81f1bc..fb8cdbd 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -29,21 +29,11 @@ - - - - - - - - - - - - - + + + + - - + + + + + + + diff --git a/pojcs101_M02039_snakey_encryption.cpp b/pojcs101_M02039_snakey_encryption.cpp new file mode 100644 index 0000000..ec1f152 --- /dev/null +++ b/pojcs101_M02039_snakey_encryption.cpp @@ -0,0 +1,31 @@ +#include +#include +#include + +using namespace std; + +string decrypt_snakey(string encrypted, int col) { + string decrypted; + for (int i = 0; i < col; i++) { + for (int offset = 0;; offset++) { + try { + decrypted += encrypted.at(i + offset * 2 * col); + decrypted += encrypted.at((offset + 1) * 2 * col - i - 1); + } catch (out_of_range&) { + break; + } + } + } + return decrypted; +} + +int main() { + ios::sync_with_stdio(false); + cin.tie(nullptr); + string encrypted; + int col; + cin >> col >> encrypted; + cout << decrypt_snakey(encrypted, col) << endl; + + return 0; +} diff --git a/pojcs101_M02431_cows_gas_leak_WRONG.cpp b/pojcs101_M02431_cows_gas_leak_WRONG.cpp new file mode 100644 index 0000000..dd093eb --- /dev/null +++ b/pojcs101_M02431_cows_gas_leak_WRONG.cpp @@ -0,0 +1,55 @@ +#include +#include +#include + +using namespace std; + +typedef pair Range; +typedef pair FuelStop; + +vector covered_ranges(const vector& fuel_stops, const int full_distance, const int initial_fuel) { + vector ranges{{0, initial_fuel}}; + ranges.reserve(fuel_stops.size()); + for (const auto& [distance, fuel_amount] : fuel_stops) { + ranges.emplace_back(full_distance - distance, full_distance - distance + fuel_amount); + } + return ranges; +} + +int min_stops(vector ranges, const int full_distance) { + sort(ranges.begin(), ranges.end()); + int answer = 0; + int current_pos = 0, max_r = -1; + for (int i = 0; i < ranges.size();) { + if (ranges[i].first <= current_pos) { + max_r = max(max_r, ranges[i].second); + if (max_r >= full_distance) { return answer - 1; } + i++; + } else { + if (max_r < current_pos) { return -1; } + answer++, current_pos = max_r, max_r = -1; + } + } + return -1; +} + +int main() { + ios::sync_with_stdio(false); + cin.tie(nullptr); + int fuel_stop_count, full_distance, initial_fuel; + cin >> fuel_stop_count; + vector fuel_stops(fuel_stop_count); + for (int i = 0; i < fuel_stop_count; i++) { + cin >> fuel_stops[i].first >> fuel_stops[i].second; + } + cin >> full_distance >> initial_fuel; + const vector ranges = covered_ranges(fuel_stops, full_distance, initial_fuel); + for (const auto& [l, r] : ranges) { + clog << "[" << l << "," << r << "] "; + } + clog << endl; + + cout << min_stops(ranges, full_distance) << endl; + + return 0; +} diff --git a/pojcs101_M02524_ubiquitous_religions_dsu.cpp b/pojcs101_M02524_ubiquitous_religions_dsu.cpp new file mode 100644 index 0000000..a4d0339 --- /dev/null +++ b/pojcs101_M02524_ubiquitous_religions_dsu.cpp @@ -0,0 +1,38 @@ +#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); + + return 0; +}