题目:
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/c780fe4bfaf5c9247dabb9ce579f299c.png#pic_center)
分析:既然给出了移动过程,那么题目就简单了。就是回溯啊。
代码:
#include<bits/stdc++.h>
using namespace std;
string s;
int m;
void init()
{
string s1(m,'o');
string s2(m,'*');
s=s1+s2;
s+='-';s+='-';
}
void f(int x1,int x2,int y1,int y2)
{
if(y2==9) return;
cout<<s<<endl;
s[x1]='-';
s[x2]='-';
s[y1]='o';
s[y2]='*';
cout<<s<<endl;
if(x1==0) return;
s[x1]='*';
s[x2]='*';
s[y1-2]='-';
s[y2-2]='-';
x1--;
x2--;
y1--;y1--;y2--;y2--;
f(x1,x2,y1,y2);
}
void f2()
{
cout<<"oooo****--";
cout<<s.substr(10,s.length()-10)<<endl;
cout<<"ooo--***o*";
cout<<s.substr(10,s.length()-10)<<endl;
cout<<"ooo*o**--*";
cout<<s.substr(10,s.length()-10)<<endl;
cout<<"o--*o**oo*";
cout<<s.substr(10,s.length()-10)<<endl;
cout<<"o*o*o*--o*";
cout<<s.substr(10,s.length()-10)<<endl;
cout<<"--o*o*o*o*";
cout<<s.substr(10,s.length()-10)<<endl;
}
int main()
{
cin>>m;
init();
f(m-1,m,m+m,m+m+1);
f2();
}