Peaceful kings

Write a program that prints all the ways to place kk kings on a n×nn \times n 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 4×44 \times 4 board:

Input

Input consists of two natural numbers n>0n > 0 and 0kn20 \le k \le n^2.

Output

Print all the ways to place kk kings on a n×nn \times n 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.

Information about the checker

You can print the solutions to this exercise in any order.

Observation

The test cases of this problem do not require a very clever algorithm.

Problem information

Author: Unknown
Translator: Salvador Roura

Generation: 2026-01-25T11:39:48.086Z

© Jutge.org, 2006–2026.
https://jutge.org