版权声明:蒟蒻的博客,留个链接就是了…… https://blog.csdn.net/qq_42817441/article/details/88240988
基于某位大佬的思想,干脆反着推,从目标状态到初始状态,移动i个盘子到j号点要 步。
目标节点肯定在最大的盘子上。
相当于是预处理吧。
#include<iostream>
#include<cmath>
using namespace std;
int x[4],h[100005],ha[100005];
int main()
{
int n,i,j;
ha[0]=1;
for(i=1;i<=100000;i++)
ha[i]=2*ha[i-1],ha[i]%=1000000; //预处理
while(cin>>n){
for(i=1;i<=3;i++)
cin>>x[i];
for(i=1;i<=3;i++)
for(j=1;j<=x[i];j++){
int c;
cin>>c;
h[c]=i;
}
int now=h[n],ne=h[n-1],ans=0;
for(i=n-1;i>0;i--,ne=h[i])
if(ne!=now){ //如果不在要到达的杆子上
ans+=ha[i-1]; //计算
ans%=1000000; //mod
now=6-ne-now; //更新now
}
cout<<h[n]<<endl<<ans<<endl;
}
return 0;
}