Board Moves

 This is solution of Codeforces problem Board Moves

 

The question says that we will be given 'n'  which will be odd & the question is based on n * n board. One figure will be placed in all cell & we have to minimize number of moves required to move all figure in one cell.

 

Best possible way to minimize is to move all figures to the center. So for n = 3 our answer will be 8.

 

For n = 5 our answer will be :


1 * 8 + 2 * 16

 

In first layer we have 8 cells & each figure can move to center in 1 move. In second layer we have 16 cell & figures can move to center in 2 moves.

 

 For n = 7  our answer will be :

 

1 * 8 + 2 * 16 + 3 * 24

 

Now coming to coding part : 

 

We will keep track of three variables one for sum, one for increasing the value by 8 & at last for increasing the value by 1.

 

Solution

No comments:

If you have any doubt or suggestion let me know in comment section.

Powered by Blogger.