UVA-696 - How Many Knights

  • UVa Online Judge 解題結果請於 Submit 後,參閱 uHunt
  • 如果你有任何建議與指教,歡迎於下方留言一起討論喔!
  • 本題選為「20170926 大學程式能力檢定 CPE」題目。

題意概要

在西洋棋裡面的騎士,走法和中國象棋的走法很類似,是走「日」字的對角格。如下圖所示,假設格子裡的 N 為騎士的所在位置,而圖中 X 為騎士可以走的下一步,所以本題希望在給定棋盤大小後,算出可以容納的最多騎士個數,且騎士之間彼此不能被攻擊到。

  X   X  
X       X
    N    
X       X
  X   X  

Input

The input consists of pairs of integers giving values for N$$, followed by a pair of zeroes.


Output

For each input pair, display the number of rows and columns in the board, and the number of knights that can be appropriately placed.


Sample Input

2 3
5 5
4 7
0 0

Sample Output

4 knights may be placed on a 2 row 3 column board.
13 knights may be placed on a 5 row 5 column board.
14 knights may be placed on a 4 row 7 column board.
profile-image
David Lu
Hello, I'm David Lu. I am a graduate student in Department of Computer Science at National Chiao Tung University, Taiwan. I am in the Networking and Sensing Systems (NSS) Lab at NCTU. If you have any question, please feel free to contact with me.
comments powered by Disqus