1 条题解

  • 0
    @ 2024-2-3 10:10:37
    #include<iostream>
    #include<cstdio>
    #include<queue>
    #include<cmath>
    #include<cstring>
    #include<bits/stdc++.h>
    using namespace std;
    int dx[]={1,-1,0,0,0};
    int dy[]={0,0,-1,1,0};
    int ans=0;
    int n,x,y,b;
    int a,v[2000];
    struct node{
    	int pos,step;
    };
    queue<node>q;
    
    void bfs(int x){
        q.push((node){x,0});
        v[x]=1;
        while(!q.empty()){
        	node top=q.front();
        	q.pop();
        	
        	if(top.pos==b){
        		cout<<top.step;
        		exit(0);
    		}
        	if(v[top.pos^(3<<(n-2))]==0){
        		v[top.pos^(3<<(n-2))]=1;
        		q.push((node){top.pos^(3<<(n-2)),top.step+1});
    		}
    		if(v[top.pos^3]==0){
        		v[top.pos^3]=1;
        		q.push((node){top.pos^3,top.step+1});
    		}
    		for(int i=2;i<n;i++){
    			if(v[top.pos^(7<<(n-i-1))]==0){
    				v[top.pos^(7<<(n-i-1))]=1;
    				q.push((node){top.pos^(7<<(n-i-1)),top.step+1});
    			}
    		}
    	}
    }
    
    int main(){
        cin>>n;
        for(int i=1;i<=n;i++){
        	cin>>x;
        	if(x) a=a|(1<<(n-i));
    	}
    	for(int i=1;i<=n;i++){
    		cin>>x;
    		if(x) b=b|(1<<(n-i));
    	}
    	bfs(a);
    	cout<<"Boring";
    }
    
    • 1

    信息

    ID
    3065
    时间
    1000ms
    内存
    256MiB
    难度
    7
    标签
    递交数
    18
    已通过
    8
    上传者