Problem Statement
给你一个宽度为w,无限高的方格。
将1到n从方格第一行第一格从左到右,从上到下依次填入。
现在每次删除一个矩形内的数字(矩形可以包括没有数字的方格),
将剩下的数字按照原来的方式从小到大填入。
问最小几步操作,可以使数字只剩下x?
数据范围:(n<=3000, x,w<=n).
Fox Ciel needs an avatar.
In her operating system she has n avatars to choose from.
They are numbered from 1 to n.
Whenever her operating system displays a set of avatars, it does so in the following way:
- The avatars will be shown in a grid, in a fixed-width window.
- The window will always have the room for exactly width columns of avatars.
- The number of rows will be the smallest necessary. (If there are X avatars to be displayed, there will be ceil(X/width) rows.)
- The avatars are shown ordered by their number, in row major order. That is, in order to look at all the avatars in numerical order, you look at the first row from left to right, then the second row from left to right, and so on.
- Note that in the last row some of the rightmost columns may be empty.
The window currently contains all n avatars.
Fox Ciel has already decided that she wants the avatar number x.
She now needs to delete all the other ones.
In a single step, she can select a sub-rectangle of the current window and delete all avatars it contains.
(She is allowed to select any rectangle, including one that contains some of the empty cells in the last row of the window.)
After each step the remaining avatars are reformatted using the above procedure.
Return the smallest number of steps in which she can achieve her goal.