Posted on

Knights on Chess Board – C Code


Problem :

Time Limit: 1 second(s) Memory Limit: 32 MB

Given an m x n chessboard where you want to place chess knights.
You have to find the number of maximum knights that can be placed
in the chessboard such that no two knights attack each other.
A chess knight can attack 8 positions in the board as shown in the picture below.

Sample Input
8 8
3 7
4 10

Output for Sample Input
Case 1: 32
Case 2: 11
Case 3: 20

See the problem in CodeShef .

Solution Algorithm :

  • For n or m equal to 1, the answer is m * n
  • For n or m equal to 2, there are special Cases.
  • For other cases, (m*n + 1) / 2, because only the different colors of the grid can   attack one another, so long as a certain color grid put full wants, pick…

View original post 103 more words


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s