You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
127 lines
3.4 KiB
C++
127 lines
3.4 KiB
C++
#define _CRT_SECURE_NO_WARNINGS
|
|
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
|
|
#include <bits/stdc++.h>
|
|
using namespace std;
|
|
#define CRP(t, x) const t &x
|
|
#define OPL(t, x) bool operator<(CRP(t, x)) const
|
|
#define FIL(x, v) memset(x, v, sizeof(x))
|
|
#define CLR(x) FIL(x, 0)
|
|
#define NE1(x) FIL(x, -1)
|
|
#define INF(x) FIL(x, 0x3f)
|
|
typedef long long ll, i64;
|
|
#define is_right tmp.zeo % 4 == 0
|
|
#define is_up tmp.zeo >= 1 && tmp.zeo <= 4
|
|
#define is_down tmp.zeo >= 13 && tmp.zeo <= 16
|
|
#define is_left tmp.zeo % 4 == 1
|
|
using namespace std;
|
|
struct lst
|
|
{
|
|
string s;
|
|
int stp;
|
|
int zeo;
|
|
};
|
|
char cg[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
|
|
map<string, int> mp;
|
|
queue<lst> q;
|
|
const int um = 15;
|
|
int main()
|
|
{
|
|
lst be;
|
|
be.s = "x123456789ABCDEF0";
|
|
be.stp = 0;
|
|
be.zeo = 16;
|
|
mp[be.s] = 0;
|
|
int cnt = 0;
|
|
q.push(be);
|
|
while (!q.empty())
|
|
{
|
|
cnt++;
|
|
lst tmp = q.front();
|
|
q.pop();
|
|
if (tmp.stp > mp[tmp.s]) continue;
|
|
bool goup = 1, godown = 1, goleft = 1, goright = 1;
|
|
if (is_right) { goright = 0; }
|
|
if (is_up) { goup = 0; }
|
|
if (is_down) { godown = 0; }
|
|
if (is_left) { goleft = 0; }
|
|
if (goup)
|
|
{
|
|
lst qins = tmp;
|
|
swap(qins.s[qins.zeo], qins.s[qins.zeo - 4]);
|
|
qins.zeo -= 4;
|
|
qins.stp++;
|
|
if (qins.stp <= um && ((!mp.count(qins.s) || mp[qins.s] > qins.stp)))
|
|
{
|
|
q.push(qins);
|
|
mp[qins.s] = qins.stp;
|
|
}
|
|
}
|
|
if (godown)
|
|
{
|
|
lst qins = tmp;
|
|
swap(qins.s[qins.zeo], qins.s[qins.zeo + 4]);
|
|
qins.zeo += 4;
|
|
qins.stp++;
|
|
if (qins.stp <= um && ((!mp.count(qins.s) || mp[qins.s] > qins.stp)))
|
|
{
|
|
q.push(qins);
|
|
mp[qins.s] = qins.stp;
|
|
}
|
|
}
|
|
if (goleft)
|
|
{
|
|
lst qins = tmp;
|
|
swap(qins.s[qins.zeo], qins.s[qins.zeo - 1]);
|
|
qins.zeo -= 1;
|
|
qins.stp++;
|
|
if (qins.stp <= um && ((!mp.count(qins.s) || mp[qins.s] > qins.stp)))
|
|
{
|
|
q.push(qins);
|
|
mp[qins.s] = qins.stp;
|
|
}
|
|
}
|
|
if (goright)
|
|
{
|
|
lst qins = tmp;
|
|
swap(qins.s[qins.zeo], qins.s[qins.zeo + 1]);
|
|
qins.zeo += 1;
|
|
qins.stp++;
|
|
if (qins.stp <= um && ((!mp.count(qins.s) || mp[qins.s] > qins.stp)))
|
|
{
|
|
q.push(qins);
|
|
mp[qins.s] = qins.stp;
|
|
}
|
|
}
|
|
}
|
|
// cout<<cnt<<endl;
|
|
for (auto x : mp)
|
|
{
|
|
int cnt = 1;
|
|
for (int i = 1; i <= 4; i++, cout << endl)
|
|
for (int j = 1; j <= 4; j++)
|
|
{
|
|
cout << x.first[cnt] << " ";
|
|
cnt++;
|
|
}
|
|
cout << ";;" << x.second << endl;
|
|
getchar();
|
|
}
|
|
int T;
|
|
scanf("%d", &T);
|
|
for (int i = 1; i <= T; i++)
|
|
{
|
|
string mm = "x";
|
|
for (int j = 1; j <= 16; j++)
|
|
{
|
|
int t;
|
|
scanf("%d", &t);
|
|
mm = mm + cg[t];
|
|
} //cout<<mm<<endl;
|
|
if (mp.count(mm))
|
|
printf("Yes\n");
|
|
else
|
|
printf("No\n");
|
|
}
|
|
return 0;
|
|
}
|