AcWing 116. 飞行员兄弟
原题链接
简单
作者:
城府_7
,
2019-05-23 15:41:07
,
所有人可见
,
阅读 802
C++ 代码
#include<cstdio>
#include<cstring>
#include<string>
#include<iostream>
#include<algorithm>
#include<queue>
#pragma warning(disable:4996)
using namespace std;
const int maxn = 105;
int a[maxn][maxn];
int b[maxn][maxn];
queue<pair<int, int>>ans,ans1;
typedef pair<int, int>tt;
int sum;
const int INF = 0x3f3f3f3f;
int main() {
char ch;
for (int i = 1; i <= 4; i++) {
for (int j = 1; j <= 4; j++) {
ch = getchar();
if (ch == '-') {
a[i][j] = 1;
}
}
getchar();
}
sum = INF;
for (int i = 1; i < (1 << 17); i++) {
int sum1 = 0;
for (int i = 1; i <= 4; i++) {
for (int j = 1; j <= 4; j++) {
b[i][j] = a[i][j];
}
}
while (!ans.empty()) {
ans.pop();
}
for (int j = 1; j <= 16; j++) {
if (i >> (j - 1) & 1) {
sum1++;
int x = j / 4 + 1;
int y = j % 4;
if (y == 0) {
y = 4;
x--;
}
for (int k = 1; k <= 4; k++) {
b[k][y] ^= 1;
}
for (int k = 1; k <= 4; k++) {
if (k != y) {
b[x][k] ^= 1;
}
}
ans.push(make_pair(x,y));
}
}
bool ok = true;
for (int j = 1; j <= 4; j++)
for (int k = 1; k <= 4; k++)
if (!b[j][k])
ok = false;
if (ok) {
if (sum1 < sum) {
ans1 = ans;
sum = sum1;
}
}
}
cout << ans1.size() << endl;
while (!ans1.empty())
{
cout << (ans1.front()).first << " " << ans1.front().second << endl;
ans1.pop();
}
return 0;
}