Logo
(追記) (追記ここまで)

6957번 - A Knightly Pursuit 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 128 MB155545.455%

문제

In chess, game pieces move about an 8ドル \times 8$ chessboard in a fashion defined by their type. The object of the game is to capture opposing pieces by landing on their squares, and eventually trapping the king piece.

In our version of the game, we shall use a variable sized board with only 2ドル$ pieces on it: A white pawn which moves relentlessly towards the top row of the chessboard one square at a time per move; and a black knight which can move from its current location in any of up to eight ways: two squares up or down and one square left or right, or one square up or down and two squares left or right. The knight must remain on the board at all times; any move that would take it off the board is therefore disallowed. In the diagram below, the knight's position is labelled $K$ and its possible moves are labelled 1ドル$ to 8ドル$.

. . . . . . .
. . 8 . 1 . .
. 7 . . . 2 .
. . . K . . .
. 6 . . . 3 .
. . 5 . 4 . .
. . . . . . .

The pawn moves first; then the knight and pawn alternate moves. The knight tries to land either on the square occupied by the pawn (a win) or on the square immediately above the pawn (a stalemate). If the pawn reaches the top row of the board the game ends immediately and the knight loses (a loss).

Write a program to determine whether the knight can win and, if it can, the minimum number of moves it must make to do so. If the knight cannot win, your program should determine if it can cause a stalemate and, if it can, the minimum number of moves it must make to do so. Finally if the knight cannot win or cause a stalemate, your program should compute the number of moves the knight makes before the pawn wins.

The first line of input contains a positive integer, $n,ドル the number of games to analyze. For each game there are six lines of input:

  • $r,ドル the number of rows in the chessboard $(3 \le r < 100)$
  • $c,ドル the number of columns in the chessboard $(2 \le c < 100)$
  • $pr,ドル the row of the starting position of the pawn $(1 \le pr \le r)$
  • $pc,ドル the column of the starting position of the pawn $(1 \le pc \le c)$
  • $kr,ドル the row of the starting position of the knight $(1 \le kr \le r)$
  • $kc,ドル the column of the starting position of the knight $(1 \le kc \le c)$

The pawn and the knight will have different starting positions. Row 1ドル$ is at the bottom of the board and Row $r$ is at the top of the board. Column 1ドル$ is at the left and column $c$ is at the right.

입력

출력

제한

예제 입력 1

3
99
99
33
33
33
35
3
3
1
1
2
3
99
99
96
23
99
1

예제 출력 1

Win in 1 knight move(s).
Stalemate in 1 knight move(s).
Loss in 2 knight move(s).

힌트

출처

Olympiad > Canadian Computing Competition & Olympiad > 1999 > CCC 1999 4번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /