Given the position of a Bishop on an 8 * 8 chessboard, the task is to count the total number of squares that can be visited by the Bishop in one move. The position of the Bishop is denoted using row and column number of the chessboard.
Input: Row = 4, Column = 4
Input: Row = 1, Column = 1
Approach: In the game of chess, a Bishop can only move diagonally and there is no restriction in distance for each move.
So, We can also say that Bishop can move in four ways i.e. diagonally top left, top right, bottom left and bottom right from current position.
We can calculate the numbers of squares visited in each move by:
Total squares visited in Top Left move = min(r, c) – 1
Total squares visited in Top Right move = min(r, 9 – c) – 1
Total squares visited in Bottom Left move = 8 – max(r, 9 – c)
Total squares visited in Bottom Right move = 8 – max(r, c)
where, r and c are the coordinates of the current position of the Bishop on the chessboard.
Below is the implementation of the above approach:
- Count distinct points visited on the number line
- Count number of squares in a rectangle
- Sum of the count of number of adjacent squares in an M X N grid
- Count number less than N which are product of perfect squares
- Count total number of even sum sequences
- Count total number of digits from 1 to n
- Count the total number of triangles after Nth operation
- Program to count number of distinct Squares and Cubes upto N
- Count total number of N digit numbers such that the difference between sum of even and odd digits is 1
- Count pairs (a, b) whose sum of squares is N (a^2 + b^2 = N)
- Check if a king can move a valid move or not when N nights are there in a modified chessboard
- Count of perfect squares of given length
- Count Magic squares in a grid
- Count of squares that can be drawn without lifting the pencil
- Count squares with odd side length in Chessboard
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : jit_t