记录编号 42200 评测结果 EEEEEEEEEE
题目名称 轮回游戏 最终得分 0
用户昵称 GravatarCloud 是否通过 未通过
代码语言 C++ 运行时间 4.879 s
提交时间 2012-09-17 11:05:54 内存使用 0.31 MiB
显示代码纯文本
#include<fstream>
#include<queue>
#include<vector>
using namespace std;
struct yu
{
	vector<int>a,b,c,d;
	string st;
};
yu tmp;
vector<int>::iterator p;
queue<yu> dq;
int main(void)
{
	ifstream fin("rotationa.in");
	ofstream fout("rotationa.out");
	vector<int> in;
	int i,n;
	while(1)
	{
		for(;dq.size();)
			dq.pop();
		in.clear();
		tmp.a.clear();
		tmp.b.clear();
		tmp.c.clear();
		tmp.d.clear();
		tmp.st.clear();
		for(i=0;i<24;i++)
		{
			fin>>n;
			if(n==0)break;
			in.push_back(n);
		}
		if(n==0&&i==0)
			break;
		tmp.a.push_back(in[0]),tmp.b.push_back(in[1]),tmp.c.push_back(in[10]),tmp.d.push_back(in[19]);
		tmp.a.push_back(in[2]),tmp.b.push_back(in[3]),tmp.c.push_back(in[9]),tmp.d.push_back(in[19]);
		tmp.a.push_back(in[6]),tmp.b.push_back(in[8]),tmp.c.push_back(in[8]),tmp.d.push_back(in[17]);
		tmp.a.push_back(in[11]),tmp.b.push_back(in[12]),tmp.c.push_back(in[7]),tmp.d.push_back(in[16]);
		tmp.a.push_back(in[15]),tmp.b.push_back(in[17]),tmp.c.push_back(in[6]),tmp.d.push_back(in[15]);
		tmp.a.push_back(in[20]),tmp.b.push_back(in[21]),tmp.c.push_back(in[5]),tmp.d.push_back(in[14]);
		tmp.a.push_back(in[22]),tmp.b.push_back(in[23]),tmp.c.push_back(in[4]),tmp.d.push_back(in[13]);
		dq.push(tmp);
		while(dq.size())
		{
			tmp=dq.front();
			n=tmp.a[2];
			if(tmp.a[3]==n&&tmp.a[4]==n&&tmp.c[3]==n&&tmp.b[2]==n&&tmp.b[3]==n&&tmp.b[4]==n&&tmp.d[3]==n)
			{
				if(tmp.st.size()==0)
					fout<<"No moves needed"<<endl;
				else
					fout<<tmp.st<<endl;
				break;
			}
			tmp.st.push_back('A');
			p=tmp.a.begin();
			tmp.a.push_back(*p);
			tmp.a.erase(p);
			tmp.c[4]=tmp.a[2];
			tmp.d[4]=tmp.a[4];
			dq.push(tmp);
			tmp=dq.front();
			tmp.st.push_back('B');
			p=tmp.b.begin();
			tmp.b.push_back(*p);
			tmp.b.erase(p);
			tmp.c[2]=tmp.b[2];
			tmp.d[2]=tmp.b[4];
			dq.push(tmp);
			tmp=dq.front();
			tmp.st.push_back('C');
			p=tmp.c.begin();
			tmp.c.push_back(*p);
			tmp.c.erase(p);
			tmp.a[2]=tmp.c[4];
			tmp.b[2]=tmp.c[2];
			dq.push(tmp);
			tmp=dq.front();
			tmp.st.push_back('D');
			p=tmp.d.begin();
			tmp.d.push_back(*p);
			tmp.d.erase(p);
			tmp.a[4]=tmp.d[4];
			tmp.b[4]=tmp.d[2];
			dq.push(tmp);
			tmp=dq.front();
			tmp.st.push_back('E');
			*p=tmp.b.back();
			tmp.b.insert(tmp.b.begin(),*p);
			tmp.b.pop_back();
			tmp.c[2]=tmp.b[2];
			tmp.d[2]=tmp.b[4];
			dq.push(tmp);
			tmp=dq.front();
			tmp.st.push_back('F');
			*p=tmp.a.back();
			tmp.a.insert(tmp.a.begin(),*p);
			tmp.a.pop_back();
			tmp.c[4]=tmp.a[2];
			tmp.d[4]=tmp.a[4];
			dq.push(tmp);
			tmp=dq.front();
			tmp.st.push_back('G');
			*p=tmp.d.back();
			tmp.d.insert(tmp.d.begin(),*p);
			tmp.d.pop_back();
			tmp.a[4]=tmp.d[4];
			tmp.b[4]=tmp.d[2];
			dq.push(tmp);
			tmp=dq.front();
			tmp.st.push_back('H');
			*p=tmp.c.back();
			tmp.c.insert(tmp.c.begin(),*p);
			tmp.c.pop_back();
			tmp.a[2]=tmp.c[4];
			tmp.b[2]=tmp.c[2];
			dq.push(tmp);
			dq.pop();
		}
	}
	fin.close();
	fout.close();
	return 0;
}