最多步数是六步
多的就输出-1
#include<cstdio>
#include<iostream>
#include<cstring>
#include<vector>
using namespace std;
/**
* 点击x时的情况
* 右边从1开始
*/
int click(int oldInfo,int x){
int newInfo=oldInfo;
int orig=7;
if(x>=2){
orig<<=(x-2);
}else{
orig=3;
}
newInfo^=orig;
return newInfo;
}
int f[6];
/**
* 在f中点击x位置
* @x 点击位置
*/
void newClick(int floor,int x){
int change1=floor-1;
int change2=floor;
int change3=floor+1;
if(change1<1)change1=-1;
if(change3>5)change3=-1;
if(change1!=-1){
int orig1=f[change1];
int new1=orig1^(1<<(x-1));
f[change1]=new1;
f[change1]=(f[change1]&31);
}
int orig2=f[change2];
int new2=click(orig2,x);
f[change2]=new2;
f[change2]=(f[change2]&31);
//printf("f[%d]=%d\n",change2,f[change2]);
if(change3!=-1){
int orig3=f[change3];
int new3=orig3^(1<<(x-1));
f[change3]=new3;
f[change3]=(f[change3]&31);
}
}
/**
* 实际使用的click
* @clickInfo 点击状态,如(11010)为点击5、4、2位置
*/
void trueClick(int floor,int clickInfo){
if(clickInfo==0)return;
for(int i=5;i>=1;i--){
if((clickInfo>>(i-1))&1){
newClick(floor,i);
}
}
}
int inputNum(){
char A='0';
char B='1';
int num=0;
int index=4;
while(char s=getchar()){
//cout<<s<<endl;
if(s!=A&&s!=B)break;
if(s==B){
num|=(1<<index);
}
index--;
}
return num;
}
void outputF(){
for(int i=1;i<=5;i++){
int nowValue=f[i];
for(int j=4;j>=0;j--){
bool now=(nowValue>>j)&1;
cout<<now;
}
cout<<endl;
}
}
int sumOne(int x){
int sum=0;
for(int i=0;i<=4;i++){
if((x>>i)&1)sum++;
}
return sum;
}
bool isAllZero(){
for(int i=1;i<=5;i++){
if(f[i]==31)continue;
return false;
}
return true;
}
int getAnother(int x){
return (x^(31));
}
int minn=2e9;
int solveNum=0;
bool isAllTrue=false;
void solve(int nowFloor,int clickSum){
solveNum++;
if(nowFloor==6){
//outputF();
if(isAllZero()){
minn=min(minn,clickSum);
if(minn==12){
isAllTrue=true;
}
}
return;
}
if(nowFloor==1){
for(int i=0;i<((1<<5)-1);i++){
trueClick(nowFloor,i);
solve(nowFloor+1,clickSum+sumOne(i));
trueClick(nowFloor,i);
}
}else{
int clickInfo=getAnother(f[nowFloor-1]);
trueClick(nowFloor,clickInfo);
solve(nowFloor+1,clickSum+sumOne(clickInfo));
trueClick(nowFloor,clickInfo);
}
// cout<<solveNum<<endl;
}
int main(){
int T;
scanf("%d",&T);
while(T--){
minn=2e9;
getchar();
for(int i=1;i<=5;i++){
int num=inputNum();
f[i]=num;
}
solve(1,0);
cout<<((minn==2e9||(minn>6))?(-1):minn)<<endl;
}
return 0;
}
int mainA(){
int T;
scanf("%d",&T);
while(T--){
minn=2e9;
getchar();
for(int i=1;i<=5;i++){
int num=inputNum();
f[i]=num;
}
trueClick(2,27);
cout<<endl;
outputF();
}
return 0;
}
大佬复习吗qwq
做的题太少了。。就会点板子