1 条题解

  • 0
    @ 2025-4-14 18:41:37

    C++ :

    #include<cstdio>
    #include<cmath>
    const int Max=4028800;
    int nodedir=0,exdir=0,n;  
    bool flag=true,visit[60353607]={0};
    struct Node{
    	bool a[10];int step;
    } map[Max],temp,end;
    int hash(Node &x){
    	int sum=0;
    	for(int i=0;i<n;i++)
    	sum+=x.a[i]*pow(6,i);
    	return sum;
    }
    bool equal(Node &x,Node &y){
    	for(int i=0;i<n;i++)
    	if(x.a[i]!=y.a[i]) return false;
    	return true;
    }
    int main(){
    	scanf("%d",&n);
    	for(int i=0;i<n;i++)
    	scanf("%d",&map[0].a[i]);
    	for(int i=0;i<n;i++)
    	scanf("%d",&end.a[i]);
    	map[0].step=0;
    	while(nodedir<=exdir&&exdir<Max&&flag){
    		for(int i=0;i<n;i++){
    			temp=map[nodedir];temp.a[i]=!temp.a[i];
    			if(i==0)	 temp.a[i+1]=!temp.a[i+1];
    			else if(i==n-1) temp.a[i-1]=!temp.a[i-1];
    			else {temp.a[i-1]=!temp.a[i-1];temp.a[i+1]=!temp.a[i+1];
    			}
    			temp.step++;
    			if(equal(temp,end)){
    				printf("%d\n",temp.step);
    				flag=false; break;
    			}
    			if(!visit[hash(temp)]){
    				visit[hash(temp)]=true;
    				map[++exdir]=temp;
    			}
    		}
    		nodedir++;
    	}
    	if(flag)  printf("Boring\n");
    	return 0;
    }
    
    • 1

    信息

    ID
    3128
    时间
    1000ms
    内存
    128MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者