题解
2023-08-26 13:09:06
发布于:广东
11阅读
0回复
0点赞
没人?那我发了?
#include <bits/stdc++.h>
using namespace std;
#define read cin
#define written cout
template <typename T> void reverse_segment(vector<T> &vec, int start, int end) {
while (start < end) {
T temp = vec[start];
vec[start] = vec[end];
vec[end] = temp;
start++;
end--;
}
}
int main() {
int n, k;
read >> n >> k;
int a1, a2;
int b1, b2;
read >> a1 >> a2 >> b1 >> b2;
vector<int> cows(n);
iota(cows.begin(), cows.end(), 1);
std::set<vector<int>> visited{cows};
while (true) {
reverse_segment(cows, a1 - 1, a2 - 1);
reverse_segment(cows, b1 - 1, b2 - 1);
if (visited.count(cows)) { break; }
visited.insert(cows);
}
int cycle_len = visited.size();
int swaps_left = k % cycle_len;
for (int s = 0; s < swaps_left; s++) {
reverse_segment(cows, a1 - 1, a2 - 1);
reverse_segment(cows, b1 - 1, b2 - 1);
}
for (int c : cows) { written << c << '\n'; }
}
这里空空如也
有帮助,赞一个