单点时限: 4.0 sec
内存限制: 256 MB
Komorebi
is one of the chief apprentice of Taiyi religion, he specially loves studying tactical deployments, so he usually practices them with his younger martial brothers.
A tactical deployment can be regarded as a matrix with
However, his younger martial brothers always forget the deployment, so Komorebi
has to move them to correct place. For each operation, Komorebi
can move one martial brother to adjacent empty position. Formally, if one of the martial brother is located at Komorebi
wants to move him:
If Komorebi
can move him to
If Komorebi
can move him to
If Komorebi
can move him to
If Komorebi
can move him to
One position is empty means that no person stands on it.
Besides,
They need to practice Komorebi
will give you the ideal deployment and the current deployment, please help Komorebi
to calculate the minimum number of operations to practice each of them.
Komorebi
是太乙教的首席大弟子,他十分精于演练阵法,也乐在其中,因此他经常与师弟们一起演练阵法。
一个阵法可以看作一个
然而,他的师弟们经常会忘记阵法,因此Komorebi
就需要将他们移动到正确的位置上。每次操作他都可以将一名师弟移动到一个相邻的格子上。具体来说,如果一名师弟在坐标为Komorebi
就可以花费一点操作点选择以下操作中的一项:
如果一个格子上没有人站着,那么我们就认为它是空的。
此外,Komorebi
也是阵法中的一员,他可以选择在任意时刻站在任意位置上,这个操作不消耗操作点,但如果他后续还想要移动的话,那么就需要遵循上述操作,此时也会消耗一点操作点。
他们需要演练Komorebi
会告诉你正确的阵法以及目前师弟们排出来的阵法,请你告诉他如果要正确地演练每一个阵法最少各需要多少操作点。
The first line contains one integer
For the following
Each position of each deployment is one of the following:
’.’: indicating an empty position.
’#’: indicating a position with a person.
Notice that the ideal deployment contains Komorebi
, but the current one doesn’t, so the number of ‘#’ in the current deployment equals to the number of ‘#’ in the ideal deployment
For each case, output one line contains one integer indicating the answer.
2 4 #... .... .... ...# ..#. .... .... .... 1 # .
2 0