Files
python/TangDou/AcWing/MinimalStep/1107_0.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

36 lines
1.1 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <bits/stdc++.h>
using namespace std;
// 交换上下两行
string A(string t) {
// 1234 5678---> 8765 4321
// 使用瞪眼大法,发现开始位置与终止位置是关于中线对称的,即0<->7,1<->6,2<->5,3<->4,这样就简单了,直接i<->7-i
for (int i = 0; i < 4; i++) swap(t[i], t[7 - i]);
return t;
}
// 将最右边的一列插入到最左边
string B(string t) {
// 1234 5678 ---> 4123 6785
// 4向上冒泡,5向后冒泡
for (int i = 3; i > 0; i--) swap(t[i], t[i - 1]);
for (int i = 4; i < 7; i++) swap(t[i], t[i + 1]);
return t;
}
// 魔板中央对的4个数作顺时针旋转
string C(string t) {
// 1234 5678 ---> 1724 5368
/*
swap(t[1], t[2]) 1234 5678 -> 1324 5678 把第一个不匹配的数字放到合适位置上
swap(t[5], t[6]) 1324 5678 -> 1324 5768 把第二个不匹配的数字放到合适位置上
swap(t[1], t[5]) 1324 5768 -> 1724 5368 回到头,再把第一个不匹配的数字放到合适位置上
*/
swap(t[1], t[2]), swap(t[5], t[6]), swap(t[1], t[5]);
return t;
}
int main() {
return 0;
}