听说灌水区大佬多
  • 板块灌水区
  • 楼主wo_hen_la
  • 当前回复2
  • 已保存回复2
  • 发布时间2023/8/31 13:48
  • 上次更新2023/11/3 00:12:45
查看原帖
听说灌水区大佬多
794701
wo_hen_la楼主2023/8/31 13:48

P2133

90分MLE

#include<bits/stdc++.h>
using namespace std;
string s1,s2;
struct node
{
	int a[6],x;
}y;
queue<node> r;
inline bool pd(node z)
{
	string s;
	for(int i=0;i<6;i++){
		s+=z.a[i]+'0';
	}
	return s==s2;
}
int main()
{
	cin>>s1>>s2;
	for(int i=0;i<6;i++){
		y.a[i]=s1[i]-'0';
	}
	y.x=0;
	r.push(y);
	bool f=0;
	while(!r.empty()){
		node z=r.front();
		r.pop();
		if(pd(z)){
			if(!f) f=1;
			else{
				cout<<z.x;
				return 0;
			}
		}
		z.x++;
		for(int i=0;i<5;i++){
			swap(z.a[i],z.a[i+1]);
			r.push(z);
			swap(z.a[i],z.a[i+1]);
		}
	}
	return 0;
}
2023/8/31 13:48
加载中...