1327:黑白棋子的移动

 

【题目描述】

有2n个棋子(n≥4)排成一行,开始位置为白子全部在左边,黑子全部在右边,如下图为n=5的情形:

○○○○○●●●●●

移动棋子的规则是:每次必须同时移动相邻的两个棋子,颜色不限,可以左移也可以右移到空位上去,但不能调换两个棋子的左右位置。每次移动必须跳过若干个棋子(不能平移),要求最后能移成黑白相间的一行棋子。如n=5时,成为:

○●○●○●○●○●

任务:编程打印出移动过程。

【输入】

输入n。

【输出】

移动过程。

【输入样例】

7

【输出样例】

step 0:ooooooo*******--
step 1:oooooo--******o*
step 2:oooooo******--o*
step 3:ooooo--*****o*o*
step 4:ooooo*****--o*o*
step 5:oooo--****o*o*o*
step 6:oooo****--o*o*o*
step 7:ooo--***o*o*o*o*
step 8:ooo*o**--*o*o*o*
step 9:o--*o**oo*o*o*o*
step10:o*o*o*--o*o*o*o*
step11:--o*o*o*o*o*o*o*
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#define sf(a) scanf("%d\n",&a)
#define e 1e-8
#define ms(a) memset(a,0,sizeof a)
#define rep(a,b,c) for(a=b;a<=c;a++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf=0x3f3f3f3f;
const int idata=100+5;
int n,ans;
char *ch;
int hollow;
int cnt;

void print()
{
    if(cnt<9)
    printf("step %d:",++cnt);
    else
    printf("step%d:",++cnt);
    for(int i=1;i<=2*n+2;i++)
        cout<>n)
    {
        int i;
        hollow=2*n+1;
        ch=new char [idata];
        for(i=1;i<=n;i++)
            ch[i]='o';
        for(i=n+1;i<=2*n;i++)
            ch[i]='*';
        ch[i+1]='-',ch[i]='-';
        printf("step 0:");
        for(i=1;i<=2*n+2;i++)
            cout<

 

你可能感兴趣的:(#,分治算法,信息学奥赛)