Write a program that prints all the ways to place kings on a board so that no king threatens another king. Remember that a king threatens all the surrounding cells, either horizontally, vertically, or diagonally.
For instance, these are some ways to place 3 kings on a board:
Input consists of two natural numbers and .
Print all the ways to place
kings on a
board so that no king threatens another king. Mark the kings with a
‘K’, and the empty cells with a dot. Print a line with ten
hyphens after every board.
You can print the solutions to this exercise in any order.
The test cases of this problem do not require a very clever algorithm.
Author: Unknown
Translator: Salvador Roura
Generation: 2026-01-25T11:39:48.086Z
© Jutge.org, 2006–2026.
https://jutge.org