The movement of black and white pieces

Source: Internet
Author: User

Title Description

There are 2n pieces (n≥4) lined up, starting as the position of 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/output format

Input format:

An integer n (n<=50)

Output format:

Several lines representing the initial state and the state of each move, with "O" for the white Child, "X" for the Sunspot, and "-" for the blank line.

Input Sample:

7

Sample output:

ooooooo*******--oooooo--******o*oooooo******--o*ooooo--*****o*o*ooooo*****--o*o*oooo--****o*o*o*oooo****--o*o* o*ooo--***o*o*o*o*ooo*o**--*o*o*o*o--*o**oo*o*o*o*o*o*o*--o*o*o*o*--o*o*o*o*o*o*o*

The example of this problem can be found in the case of N < 4, which will move the o* of a[n-1] and A[n] and move the * * * of a[2n-1] and a[2n-2. In this case, the output of N >= 4 can be recycled.

As for the N < 4, just the first half of the n-4, the latter part plus a o* on the line.

On the Code

1#include <cstdio>2#include <iostream>3#include <cmath>4#include <cstring>5#include <algorithm>6 using namespacestd;7 Const intMAXN =10005;8 CharA[MAXN];9 intN;Ten voidInitintN) One { A      for(inti =0; I < n; ++i) A[i] ='o'; -      for(inti = n; I <2N ++i) A[i] ='*'; -a[2* N] = a[2* n +1] ='-'; the     return; - } - voidSolveintN) - { +A[n-1] = A[n] ='-'; -a[2* N] ='o';  +a[2* n +1] ='*'; Aprintf"%s\n", a); atA[n-1] = A[n] ='*'; -a[2N1] = a[2N2] ='-'; -printf"%s\n", a); -     return; - } - voidfstnoutput () in { -printf"ooo--***o*"); to      for(inti =1; I <= N-4; ++i) printf ("o*"); +printf"\ n"); -printf"ooo*o**--*"); the      for(inti =1; I <= N-4; ++i) printf ("o*"); *printf"\ n"); $printf"o--*o**oo*");Panax Notoginseng      for(inti =1; I <= N-4; ++i) printf ("o*"); -printf"\ n"); theprintf"o*o*o*--o*"); +      for(inti =1; I <= N-4; ++i) printf ("o*"); Aprintf"\ n"); theprintf"--o*o*o*o*"); +      for(inti =1; I <= N-4; ++i) printf ("o*"); -printf"\ n"); $     return; $ } - intMain () - { thescanf"%d", &n); - init (n);Wuyi     intm =N; theprintf"%s\n", a); -      while(M >4) Wu     { - solve (m); Aboutm--; $     } - fstnoutput (); -     return 0; -}

I think the problem is quite water.

But in the sub-label when I hesitated for a long time, and finally feel it even recursive recursive, although this problem is I am learning to divide the time out. Awkward

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.