#define M (19+2)
void InitChess( int chess[], int m )
{
chess[ 0 ] = 0;
chess[ m-1 ] = 0;
for( int i = 1; i < m-1; i++ )
{
chess[ i ] = i/(m/2)+1;
}
}
void DispChess( int chess[], int m )
{
for( int i = 0; i < m; i++)
{
cout<<chess[ i ]<<",";
}
cout<<endl;
}
void MoveToSpace( int chess[], int space, int index )
{
if( space != index && chess[index] )
{
chess[ space ] = chess[ index ] ;
chess[ index ] = 0;
//DispChess( chess, M );
}
}
void MoveChess( int chess[], int space1, int space2, int i, int j )
{
if( i < 0 || j > M-1 )
{
return;
}
else
{
MoveToSpace( chess, space2, i );
MoveToSpace( chess, space1, j );
DispChess( chess, M );
MoveToSpace( chess, i, space1 );
MoveToSpace( chess, j, space2 );
DispChess( chess, M );
MoveChess( chess, space1, space2, i-2, j+2 );
}
}
void TestChessMove()
{
int chess[ M ] ;
InitChess( chess, M );
DispChess( chess, M );
if( M%2 )
{
MoveChess( chess, 0, M-1, M/2-2, M/2+1 );
}
else
{
MoveChess( chess, 0, M-1, M/2-2, M/2+1 );
}
}
#include<stdio.h>
#include<stdlib.h>
enum Color{ BLUE, WHITE };
#define COLOROF(a) (a>0 ? WHITE : BLUE)
void display(int* a, int n);
int main(){
// - n ~ n
int n;
if( !scanf("%d", &n) ){
return 0;
}
getchar();
if( n < 1 || n > 10000 ){
printf("don't cheat me as a fool!");
return 0;
}
// represent the nails in the axis
int *a = NULL;
if(! ( a = (int*)malloc(sizeof(int)*(2*n+1)) ) ){
return 0;
}
for(int i=0; i<2*n+1; i++){
a[i] = i - n;
}
// initize position of the space
int position = n;
// last color
Color last = BLUE;
// routine
while(1){
display(a, n);
//left boundary
if( position == 0 ){
if( COLOROF(a[1]) == WHITE ){
a[0] = a[1];
a[1] = 0;
position = 1;
continue;
}else if(COLOROF(a[2]) == WHITE){
a[0] = a[2];
a[2] = 0;
position = 2;
continue;
}
break;
//right boundary
}else if( position == 2*n ) {
if( COLOROF(a[2*n-1 ]) == BLUE ){
a[2*n] = a[2*n-1];
a[2*n-1] = 0;
position = 2*n -1;
last = WHITE;
continue;
}else if( COLOROF(a[2*n-2]) == BLUE ){
a[2*n] = a[2*n-2];
a[2*n-2] = 0;
position = 2*n -2;
last = BLUE;
continue;
}
break;
//between the ones of the same color
}else if( COLOROF(a[position-1]) == COLOROF(a[position+1]) ){
if( COLOROF(a[position-1]) == BLUE ){
if(position+2<2*n+1 && COLOROF(a[position+2]) == WHITE ){
a[position] = a[position+2];
a[position+2] = 0;
position += 2;
last = WHITE;
continue;
}
a[position] = a[position-1];
a[position-1] = 0;
position -= 1;
last = BLUE;
continue;
}else{
if( position-2>=0 && COLOROF(a[position-2]) == BLUE ){
a[position] = a[position-2];
a[position-2] = 0;
position -= 2;
last = BLUE;
continue;
}
a[position] = a[position+1];
a[position+1] = 0;
position += 1;
last = WHITE;
continue;
}
break;
//between the ones of different colors
}else{
if( last == BLUE ){
if( COLOROF(a[position-1]) == BLUE ){
a[position] = a[position-1];
a[position-1] = 0;
position -= 1;
continue;
}else if( position-2>=0 && COLOROF(a[position-2]) == BLUE ){
a[position] = a[position-2];
a[position-2] = 0;
position -= 2;
continue;
}else if( position+2<2*n+1 && COLOROF(a[position+2])==WHITE ){
a[position] = a[position+2];
a[position+2] = 0;
position += 2;
last = WHITE;
continue;
}
break;
}else{
if( COLOROF(a[position+1]) == WHITE ){
a[position] = a[position+1];
a[position+1] = 0;
position += 1;
continue;
}else if( position+2<2*n+1 && COLOROF(a[position+2]) == WHITE ){
a[position] = a[position+2];
a[position+2] = 0;
position += 2;
continue;
}else if( position-2>=0 && COLOROF(a[position-2])==BLUE ){
a[position] = a[position-2];
a[position-2] = 0;
position -= 2;
continue;
}
break;
}
break;
}
}
getchar();
return 0;
}
void display(int* a, int n){
for(int i=0; i<2*n+1; i++){
printf("%3d ", a[i]);
}
printf("\n");
}