Knight’s Move

시간 제한2초메모리 제한1024 MB

요약
두 모서리 칸이 사라진 n x n 체스판에서 두 세계를 오가는 포털을 이용해 2n^2-4개 칸을 정확히 한 번씩 방문하는 닫힌 나이트 투어를 구성한다.
난이도

보통10점 중 7점

유형
구현, 시뮬레이션, 그리디, 완전 탐색
정답자
아직 제출이 없습니다

문제

Several years ago a chessboard was a square n×nn \times n in size (considering that nn was even), divided into squares 1×11 \times 1 in size. However, after all these years many things have changed in the Chess Kingdom.

The magical progress never stops and during the trials of the newest mass destruction weapon two corner squares of a chessboard, (1,1)(1,1) and (n,n)(n,n), were destroyed. Besides, the court magicians learned about a parallel world's existence – the so-called {\itshape Through the Looking Glass}, located at the other side of the board. They even learned to move from any chessboard square to the corresponding Through the Looking Glass square (to the square that is located exactly under the given square) and back again using special portals.

The White King wanted to visit once more all the squares of his kingdom with his devoted friend. His friend, that is, the Knight moves according to usual chess rules, namely: first it moves two squares in one direction, then changes the movement direction by 90 degrees (to the left or to the right) and moves one other square. In the Through the Looking Glass the Knight moves in perfectly the same manner. Besides, the King has a pocket portal using which he and the Knight can travel to Through the Looking Glass and back. We have to note that using the portal, as well as the Knight's move, is considered to be a move as well.

Help the White King and find some movement path. Each of the 2n2−42n^2-4 chessboard squares should be visited exactly once. Besides, the path should be closed, that is, one should be able to go from the first square of the path to the last one in one move. The court Wisemen proved that such path exists.

입력

You are given an even integer nn (4≤n≤1004 \le n \le 100).

출력

Print 2n2−42n^2-4 lines. The ii-th line should describe the Knight's position at the beginning of the ii-th move in the following format: xx yy ww (1≤x,y≤n,0≤w≤11 \le x, y \le n, 0 \le w \le 1). xx and yy are the coordinates of the square, ww is the world where the Knight and the King are located: 00 for the normal world and 11 for Through the Looking Glass. All squares should be different. There shouldn't be such squares as "1 1 0", "1 1 1", "n n 0", "n n 1". It is allowed to start the path from any cell. See the sample for clarifications.

If there are several solutions, print any of them.

예제1

  1. 예제 1

    입력
    4
    
    예상 출력
    3 1 0
    4 3 0
    4 3 1
    3 1 1
    2 3 1
    2 3 0
    4 2 0
    3 4 0
    3 4 1
    4 2 1
    2 1 1
    1 3 1
    3 2 1
    2 4 1
    1 2 1
    3 3 1
    1 4 1
    2 2 1
    4 1 1
    4 1 0
    2 2 0
    1 4 0
    3 3 0
    2 1 0
    1 3 0
    3 2 0
    2 4 0
    1 2 0