错在哪?求大神指路
查看原帖
错在哪?求大神指路
1251853
linglu1YGking楼主2024/9/23 17:25
#include<bits/stdc++.h>
using namespace std;
int a[10][5];
int ans=0;
bool vis[100005]={false};
inline void memory(int b,int c,int d,int e,int f){
	int x;
	x=10000*b+c*1000+d*100+e*10+f;
	if(!vis[x]){
	ans++;
	vis[x]=true;
	}
	return;
}
void bfs(int b,int c,int d,int e,int f){
	for(int i=0;i<=9;i++){
		if(i!=b)
			memory(i,c,d,e,f);
		if(i!=c)
		    memory(b,i,d,e,f);
		if(i!=d)
			memory(b,c,i,e,f);
		if(i!=e)
			memory(b,c,d,i,f);
		if(i!=f)
			memory(b,c,d,e,i);
	}
	for(int i=1;i<=8;i++){
		if((b+i)%9!=b || (c+i)%9!=c)
		    memory((b+i)%9,(c+i)%9,d,e,f);
		if((c+i)%9!=c || (d+i)%9!=d)
		    memory(b,(c+i)%9,(d+i)%9,e,f);
		if((d+i)%9!=d || (e+i)%9!=e)
		    memory(b,c,(d+i)%9,(e+i)%9,f);
		if((e+i)%9!=e || (f+i)%9!=f)
		    memory(b,c,d,(e+i)%9,(f+i)%9);
	}
}

int main(){
	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
	for(int j=0;j<5;j++)
	cin>>a[i][j];
	bfs(a[i][0],a[i][1],a[i][2],a[i][3],a[i][4]);
	cout<<ans;
	}
	
	return 0;
} 
2024/9/23 17:25
加载中...