Suppose there is a chessboard with dimensions $n\times n$ and you put rooks on the chessboard such that they collectively attack $m$ squares on that chessboard (a rook attacks the square it is on, too). Given $n$ and $m$, how can you determine how many rooks must be placed on the chessboard, and where to put them?
For example, let's say that the board dimensions are $3\times 3$ and you have to cover $9$ squares on the board by placing rooks. To do this, or to simply cover the board with rooks such that there are no safe squares, you can put $3$ rooks in the coordinates $(1,1);(1,2);(1,3)$ on the board (the first number in the coordinate is the column number, the second is the row number). That way, since a rook attacks all squares in the same row and column as where it stands, all $9$ squares are attacked.
But how can you find the optimal coordinates for any $n$ and $m$ with an algorithm?
You can just greedily put the rooks down a diagonal until you cover enough squares. The first rook will cover $2n-1$ squares, the next will cover $2n-3$ new ones, then $2n-5$ and so on. For $k$ rooks you will cover $2kn-k^2$ until $k$ becomes $n$. Any way of placing the rooks that doesn't have them in the same row or column will achieve the same number.
Added: If you have rooks in $p$ rows and $q$ columns you will attack $np+nq-pq$ squares. For $n=6$, then you can cover $0,11,16,20,21,24,26,27,28,30,31,32,33,34,35,36$ cells