求助,莫名WA点
查看原帖
求助,莫名WA点
239192
淸梣ling楼主2021/3/30 18:43

不知道哪里错了,请各位大佬康康

#include<iostream>
#include<cstdio>
using namespace std;

int z[8]={7,8,9,12,13,16,17,18};
int m[8][8]={{1,3,7,12,16,21,23},{2,4,9,13,18,22,24},{11,10,9,8,7,6,5},{20,19,18,17,16,15,14},{24,22,18,13,9,4,2},{23,21,16,12,7,3,1},{14,15,16,17,18,19,20},{5,6,7,8,9,10,11}};
int t[30];
int put[300000];

void move(int x)
{
	int tmp=t[m[x][0]],i;
	for(i=1;i<7;i++)
	t[m[x][i-1]]=t[m[x][i]];
	t[m[x][i-1]]=tmp;
}
void remo(int x)
{
	int tmp=t[m[x][6]],i;
	for(i=5;i>=0;i--)
	t[m[x][i+1]]=t[m[x][i]];
	t[m[x][i+1]]=tmp;
}
int check()
{
	int num[4]={},i;
	for(i=0;i<8;i++)
	 ++num[t[z[i]]];
	return max(num[1],max(num[2],num[3]));
}
bool dfs(int k,int depth)
{
	if(check()==8) return 1;
	if(k+8-check()>depth) return 0;
	for(int i=0;i<8;i++)
	{
		move(i);
		put[k]=i+'A';
		if(dfs(k+1,depth)) return 1;
		remo(i);
	}
	return 0;
}
int main()
{
	int i;
	int ans;
	
	cin>>t[1];
	while(t[1])
	{
		for(i=2;i<=24;i++)
		cin>>t[i];
		
		ans=0;
		while(1)
		{
			if(dfs(1,ans))
				break;
			++ans;
		}
		if(ans)
		 for(i=1;i<=ans;i++)
		  putchar(put[i]);
		else
		 printf("No moves needed");
		printf("\n%d\n",t[7]);
		
		cin>>t[1];
	}
	return 0;
}
2021/3/30 18:43
加载中...