AcWing 116. 飞行员兄弟
原题链接
简单
作者:
Darius
,
2021-04-11 19:34:21
,
所有人可见
,
阅读 292
#include <bits/stdc++.h>
using namespace std;
string s[4];
vector<int> a(4);
void turn(int x, int y) {
a[x] = a[x] ^ (1 << y);
for (int i = 0; i < 4; ++i) {
a[x] = a[x] ^ (1 << i);
a[i] = a[i] ^ (1 << y);
}
}
int main() {
for (int i = 0; i < 4; ++i) {
cin >> s[i];
for (int j = 0; j < 4; ++j)
a[i] = a[i] * 2 + (s[i][j] == '+' ? 0 : 1);
}
vector<pair<int, int> > ans;
for (int i = 0; i < (1 << 16); ++i) {
vector<pair<int, int> > tmp;
vector<int> b = a;
for (int j = 0; j < 16; ++j) {
if ((i >> j & 1) == 1) {
int x = j / 4, y = j % 4;
tmp.push_back({x + 1, 4 - y});
turn(x, y);
}
}
int f = 1;
for (int j = 0; j < 4; ++j)
if (a[j] != (1 << 4) - 1) {
f = 0;
break;
}
if (f && (ans.size() == 0 || tmp.size() < ans.size()))
ans = tmp;
a = b;
}
cout << ans.size() << endl;
sort(ans.begin(), ans.end());
for (auto it : ans) cout << it.first << ' ' << it.second << endl;
return 0;
}