MOOC算法练习题——特殊的密码锁

```

#include

#include

#include

#include

#include

const int N=3000+20;

using namespace std;

int tot,ans1=0,ans2=0,len;

char a[N],b[N];

int x[N],y[N];

void init(){

    tot=0;

        for(int i=0;i

        {

            x[i]=a[i]-48;

            y[i]=b[i]-48; 

        }

}

int main(){

    scanf("%s",a);

    gets(b);

    scanf("%s",b);

    len=strlen(a);

        init();

        tot++;

        x[0]=x[0]^1;

        x[1]=x[1]^1;

        for(int i=0;i

            if(x[i]!=y[i]){

                tot++;

                x[i]^=1;

                x[i+1]^=1;

                x[i+2]^=1;

            }

        }

        if(x[len-1]==y[len-1]) ans1=tot;

        init();

        for(int i=0;i

            if(x[i]!=y[i]){

                tot++;

                x[i]^=1;

                x[i+1]^=1;

                x[i+2]^=1;

            }

        }

        if(x[len-1]==y[len-1]) ans2=tot;

    if(!ans1&&!ans2) printf("impossible");

    else if(!ans1||!ans2) printf("%d",max(ans1,ans2));

    else printf("%d",min(ans1,ans2));

    return 0;

}

```

你可能感兴趣的:(MOOC算法练习题——特殊的密码锁)