"Example 7.6" the movement of black and white pieces

Source: Internet
Author: User

"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"&LT;&LT;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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.