求条
查看原帖
求条
703115
d909RCA楼主2024/4/27 11:34
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define Ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define mb pair<pair<pair<int,int>,pair<int,int> >,pair<pair<int,int>,pair<int,int> > >
int t1(mb a){return a.first.first.first;} 
int t2(mb a){return a.first.first.second;} 
int t3(mb a){return a.first.second.first;} 
int t4(mb a){return a.first.second.second;} 
int t5(mb a){return a.second.first.first;} 
int t6(mb a){return a.second.first.second;} 
int t7(mb a){return a.second.second.first;} 
int t8(mb a){return a.second.second.second;} 
bool operator ==(mb a,mb b)
{
	return (t1(a)==t1(b))&&(t2(a)==t2(b))&&(t3(a)==t3(b))&&(t4(a)==t4(b))&&(t5(a)==t5(b))&&(t6(a)==t6(b))&&(t7(a)==t7(b))&&(t8(a)==t8(b));
}
queue<pair<mb,pair<int,string> > > q;
map <mb,bool> v;
signed main()
{
	mb d;
	cin>>d.first.first.first>>d.first.first.second>>d.first.second.first>>d.first.second.second>>d.second.first.first>>d.second.first.second>>d.second.second.first>>d.second.second.second;
	v[{{{1,2},{3,4}},{{8,7},{6,5}}}]=1;
	q.push({{{{1,2},{3,4}},{{8,7},{6,5}}},{0,""}});
	while(!q.empty())
	{
		auto x=q.front();
		if(x.first==d)
		{
			cout<<x.second.first<<endl;
			cout<<x.second.second<<endl;
			return 0;
		}
		if(!v[{{{t5(x.first),t6(x.first)},{t7(x.first),t8(x.first)}},{{t1(x.first),t2(x.first)},{t3(x.first),t4(x.first)}}}])
		{
			q.push({{{{t5(x.first),t6(x.first)},{t7(x.first),t8(x.first)}},{{t1(x.first),t2(x.first)},{t3(x.first),t4(x.first)}}},{x.second.first+1,x.second.second+'A'}});
			v[{{{t5(x.first),t6(x.first)},{t7(x.first),t8(x.first)}},{{t1(x.first),t2(x.first)},{t3(x.first),t4(x.first)}}}]=1;
		}
		if(!v[{{{t4(x.first),t1(x.first)},{t2(x.first),t3(x.first)}},{{t8(x.first),t5(x.first)},{t6(x.first),t7(x.first)}}}])
		{
			q.push({{{{t4(x.first),t1(x.first)},{t2(x.first),t3(x.first)}},{{t8(x.first),t5(x.first)},{t6(x.first),t7(x.first)}}},{x.second.first+1,x.second.second+'B'}});
			v[{{{t4(x.first),t1(x.first)},{t2(x.first),t3(x.first)}},{{t8(x.first),t5(x.first)},{t6(x.first),t7(x.first)}}}]=1;
		}
		if(!v[{{{t1(x.first),t6(x.first)},{t2(x.first),t4(x.first)}},{{t5(x.first),t7(x.first)},{t3(x.first),t8(x.first)}}}])
		{
			q.push({{{{t1(x.first),t6(x.first)},{t2(x.first),t4(x.first)}},{{t5(x.first),t7(x.first)},{t3(x.first),t8(x.first)}}},{x.second.first+1,x.second.second+'C'}});
			v[{{{t1(x.first),t6(x.first)},{t2(x.first),t4(x.first)}},{{t5(x.first),t7(x.first)},{t3(x.first),t8(x.first)}}}]=1;
		}
		q.pop();
	}
	return 0;
}

2024/4/27 11:34
加载中...