1
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
.venv
|
||||
/*.exe
|
||||
/*.dSYM
|
||||
|
||||
# 忽略 linux 编译产物
|
||||
/*
|
||||
|
||||
Generated
+21
-15
@@ -29,21 +29,11 @@
|
||||
</configurations>
|
||||
</component>
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="4491295e-723c-4e0b-b7b4-9be1cbde5db8" name="更改" comment="fix gitignore">
|
||||
<change afterPath="$PROJECT_DIR$/.idea/codeStyles/codeStyleConfig.xml" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/.idea/exercises.iml" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/pojcs101_M01088_ski.cpp" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/pojcs101_M01088_ski_WRONG.cpp" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/pojcs101_M01321_chest_grid.cpp" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/pojcs101_M01328_radar_greedy.cpp" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/pojcs101_M01328_radar_greedy_WRONG.cpp" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/pojcs101_M01852_ants_falling.cpp" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/pojcs101_M01922_ride_follower.cpp" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.gitignore" beforeDir="false" afterPath="$PROJECT_DIR$/.gitignore" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/editor.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/editor.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/inspectionProfiles/Project_Default.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/inspectionProfiles/Project_Default.xml" afterDir="false" />
|
||||
<list default="true" id="4491295e-723c-4e0b-b7b4-9be1cbde5db8" name="更改" comment="1">
|
||||
<change afterPath="$PROJECT_DIR$/pojcs101_M02039_snakey_encryption.cpp" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/pojcs101_M02431_cows_gas_leak_WRONG.cpp" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/pojcs101_M02524_ubiquitous_religions_dsu.cpp" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/pojcs101_M01002_memorable_number.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/pojcs101_M01002_memorable_number.cpp" afterDir="false" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
@@ -107,6 +97,8 @@
|
||||
"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_M02692.cpp.executor": "Run",
|
||||
"C/C++ 文件.pojcs101_M02692_12_coins.cpp.executor": "Run",
|
||||
"CMake 应用程序.exercises.executor": "Run",
|
||||
@@ -138,7 +130,7 @@
|
||||
<recent name="$PROJECT_DIR$" />
|
||||
</key>
|
||||
</component>
|
||||
<component name="RunManager" selected="C/C++ 文件.pojcs101_M01922_ride_follower.cpp">
|
||||
<component name="RunManager" selected="C/C++ 文件.pojcs101_M02431_cows_gas_leak.cpp">
|
||||
<configuration name="pojcs101_M01328_radar_greedy.cpp" type="CppFileRunConfiguration" factoryName="CppFileRunConfiguration" temporary="true" REDIRECT_INPUT="false" ELEVATE="false" USE_EXTERNAL_CONSOLE="false" EMULATE_TERMINAL="false" PASS_PARENT_ENVS_2="true" PROJECT_NAME="exercises" TARGET_NAME="pojcs101_M01328_radar_greedy.cpp" CONFIG_NAME="pojcs101_M01328_radar_greedy.cpp">
|
||||
<option name="sourceFile" value="pojcs101_M01328_radar_greedy.cpp" />
|
||||
<method v="2">
|
||||
@@ -157,8 +149,22 @@
|
||||
<option name="com.jetbrains.cidr.cpp.runfile.CppFileBuildBeforeRunTaskProvider$BasicBuildBeforeRunTask" enabled="true" />
|
||||
</method>
|
||||
</configuration>
|
||||
<configuration name="pojcs101_M02039_snakey_encryption.cpp" type="CppFileRunConfiguration" factoryName="CppFileRunConfiguration" temporary="true" REDIRECT_INPUT="false" ELEVATE="false" USE_EXTERNAL_CONSOLE="false" EMULATE_TERMINAL="false" PASS_PARENT_ENVS_2="true" PROJECT_NAME="exercises" TARGET_NAME="pojcs101_M02039_snakey_encryption.cpp" CONFIG_NAME="pojcs101_M02039_snakey_encryption.cpp">
|
||||
<option name="sourceFile" value="pojcs101_M02039_snakey_encryption.cpp" />
|
||||
<method v="2">
|
||||
<option name="com.jetbrains.cidr.cpp.runfile.CppFileBuildBeforeRunTaskProvider$BasicBuildBeforeRunTask" enabled="true" />
|
||||
</method>
|
||||
</configuration>
|
||||
<configuration name="pojcs101_M02431_cows_gas_leak.cpp" type="CppFileRunConfiguration" factoryName="CppFileRunConfiguration" temporary="true" REDIRECT_INPUT="false" ELEVATE="false" USE_EXTERNAL_CONSOLE="false" EMULATE_TERMINAL="false" PASS_PARENT_ENVS_2="true" PROJECT_NAME="exercises" TARGET_NAME="pojcs101_M02431_cows_gas_leak.cpp" CONFIG_NAME="pojcs101_M02431_cows_gas_leak.cpp">
|
||||
<option name="sourceFile" value="pojcs101_M02431_cows_gas_leak.cpp" />
|
||||
<method v="2">
|
||||
<option name="com.jetbrains.cidr.cpp.runfile.CppFileBuildBeforeRunTaskProvider$BasicBuildBeforeRunTask" enabled="true" />
|
||||
</method>
|
||||
</configuration>
|
||||
<recent_temporary>
|
||||
<list>
|
||||
<item itemvalue="C/C++ 文件.pojcs101_M02431_cows_gas_leak.cpp" />
|
||||
<item itemvalue="C/C++ 文件.pojcs101_M02039_snakey_encryption.cpp" />
|
||||
<item itemvalue="C/C++ 文件.pojcs101_M01922_ride_follower.cpp" />
|
||||
<item itemvalue="C/C++ 文件.pojcs101_M01852_ants_falling.cpp" />
|
||||
<item itemvalue="C/C++ 文件.pojcs101_M01328_radar_greedy.cpp" />
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <stdexcept>
|
||||
|
||||
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;
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
using namespace std;
|
||||
|
||||
typedef pair<int, int> Range;
|
||||
typedef pair<int, int> FuelStop;
|
||||
|
||||
vector<Range> covered_ranges(const vector<FuelStop>& fuel_stops, const int full_distance, const int initial_fuel) {
|
||||
vector<Range> 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<Range> 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<FuelStop> 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<Range> 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;
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
|
||||
class Dsu {
|
||||
public:
|
||||
struct Node {
|
||||
size_t parent, size;
|
||||
};
|
||||
|
||||
vector<Node> 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;
|
||||
}
|
||||
Reference in New Issue
Block a user