题目链接
思路
明天补
代码
#include<bits/stdc++.h>
using namespace std;
const int N = 10;
char g[N][N];
char backup[N][N];
int ans = 0x3f3f3f3f;
vector<pair<int, int>> v;
int get(int x, int y)
{return x * 4 + y;
}
void turn (int x, int y)
{int dx = x;int dy = y;if (g[dx][dy] == '-') g[dx][dy] = '+';else g[dx][dy] = '-';dx = x;dy = y;while (1){dx = dx - 1;dy = dy;if (dx < 0 || dx >= 4 || dy < 0 || dy >= 4){break;}if (g[dx][dy] == '-') g[dx][dy] = '+';else g[dx][dy] = '-';}dx = x;dy = y;while (1){dx = dx + 1;dy = dy;if (dx < 0 || dx >= 4 || dy < 0 || dy >= 4){break;}if (g[dx][dy] == '-') g[dx][dy] = '+';else g[dx][dy] = '-';}dx = x;dy = y;while (1){dx = dx ;dy = dy - 1;if (dx < 0 || dx >= 4 || dy < 0 || dy >= 4){break;}if (g[dx][dy] == '-') g[dx][dy] = '+';else g[dx][dy] = '-';}dx = x;dy = y;while (1){dx = dx ;dy = dy + 1;if (dx < 0 || dx >= 4 || dy < 0 || dy >= 4){break;}if (g[dx][dy] == '-') g[dx][dy] = '+';else g[dx][dy] = '-';}
}
int main()
{for (int i = 0; i < 4; i ++ ) cin >> g[i];for (int op = 0; op < 1 << 16; op ++ ){
// cout << op;vector<pair<int, int>> p1;memcpy(backup, g, sizeof g);int num = 0;//这里采用遍历坐标的方法,访问每一位for (int i = 0; i < 4; i ++ ){for (int j = 0; j < 4; j ++ ){int x = get(i, j);
// cout << x << endl;if (op >> x & 1 == 1){
// cout << 2 << endl;turn(i, j);
// cout << i << " " << j << endl;
// for (int xx = 0; xx < 4; xx ++ )
// {
// for (int yy = 0; yy < 4; yy ++ )
// {
// cout << g[xx][yy];
// }
// cout << endl;
// }
// cout << endl;num ++;p1.push_back({i, j});
// cout << i << " " << j << endl;}}}
// cout << num << endl;
// for (auto i : v)
// {
// cout << i.first << " " << i.second << endl;
// }int f = 0;for (int i = 0; i < 4; i ++ ){for (int j = 0; j < 4; j ++ ){if (g[i][j] == '+'){f = 1;break;}}} if (!f){if (num <= ans){v = p1;ans = num;}}memcpy(g, backup, sizeof backup);}cout << ans << endl;for (auto i : v){cout << i.first + 1 << " " << i.second + 1 << endl;}return 0; }