"Example 7.6" black and White pawn Mobile Link: http://ybt.ssoier.cn:8088/problem_show.php?pid=1327
Time limit: Ms Memory limit: 65536 KB
"Title description"
There are 2n pieces (n≥4) in a row, the starting position for the white child all on the left, sunspots all on the right, as in the case of n=5:
00000
The rule of moving chess piece is: Each time must move the adjacent two pieces, the color is unlimited, can move to the left also can move to the vacancy, but cannot exchange two pieces of the left and right position. Each move must skip several pieces (cannot be translated), requiring the final move to a black-and-white line of pieces. such as n=5, become:
0 0 0) 0 0
Task: Programming prints out the move process.
Input
Enter N.
Output
The move process.
"Input Sample"
7
"Output Example"
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*
The puzzle: According to the sample must first remove many pieces, moved to four a group of
#include <iostream>#include<cstring>#include<cstdio>#include<iomanip>using namespacestd;intN,sp,step;Chara[101];voidprint () {cout<<"Step"<<SETW (2) <<step<<":"; for(intI=1; i<=2*n+2; i++) printf ("%c", A[i]); cout<<Endl; Step++;}voidIntiintN) { for(intI=1; i<=n;i++) a[i]='o'; for(inti=n+1; i<=2*n;i++) a[i]='*'; a[2*n+1]=a[2*n+2]='-'; SP=2*n+1; Print ();}voidmvintk) {A[SP]=a[k];a[sp+1]=a[k+1]; A[K]='-'; a[k+1]='-'; SP=K; Print ();}voidWorkintN) { if(n==4) {MV (4); MV (8); MV (2); MV (7); MV (1); } Else{MV (n); MV (2*n-1); Work (n1); }}intMain () {CIN>>N; Inti (n); Work (n);}
"Example 7.6" the movement of black and white pieces