用的bfs,看看第一个字符串能不能经过广搜找到第二个,两个增量数组分别是从上往下转,从左往右转
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mk make_pair
#define sz(x) ((int) (x).size())
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pa;
int dx[6] = {4, -1, 0, 0, 1, -4};
int dy[6] = {0, 1, 2, -2, -1, 0};
bool bfs(string s1, string s2) {
map<string, int> mp;
mp[s1] = 1;
queue<string> q;
q.push(s1);
while (!q.empty()) {
string s = q.front();
q.pop();
if (s == s2) return true;
string str;
for (int i = 0; i < 6; i++) str += s[i + dx[i]];
if (mp.find(str) == mp.end()) { mp[str] = 1; q.push(str); }
str.erase();
for (int i = 0; i < 6; i++) str += s[i + dy[i]];
if (mp.find(str) == mp.end()) { mp[str] = 1; q.push(str); }
}
return false;
}
int main() {
string s;
while (cin >> s) {
if (bfs(s.substr(0, 6), s.substr(6, 6))) cout << "TRUE" << endl;
else cout << "FALSE" << endl;
}
return 0;
}