Cow's conference(translated by:LydiaCCC)

Cow's conference(translated by:LydiaCCC)

Farmer John(FJ)'s farm is an area shaped as a rectangular net with R rows and C columns, and the cows are distributed in different grids. They’re allowed to move around except leaving the farm.
Given that each grid has 8 neighborhoods and the cows are able to go to whichever neighborhood every time it moves.
To discuss next month’s milk yield, FJ decides to hold a meeting and gathered all the cows in a grid.
Nevertheless, FJ loves his cows and doesn't want to make them tired. So the goal is to minimize the steps the cows take to get to the meeting place.
Given n+1 rows, the first row includes 3 positive integers R、C、N, respectively indicates the number of rows, columns and cows of the farm. 1<=R,C<=100,1<=N<=R*C.
The following n rows each includes 2 positive integers xi and yi, representing the row and column number of the ith cow. 1=<xi<=R,1=<yi<=C.
Output an integer to indicate the minimum number of steps which is needed for the cows to get to the meeting place.

Example:
Input:

3 3 2
1 3
3 1

Output:

2 

Explanation:
The corresponding matrix distribution (the distribution of the farm) is as follows.
OOC
OXO
COO
‘C’ refers to the cows. Apparently, it is feasible to take the least steps when meeting at X and the result is 2.


Special thanks: this is translated selflessly by LydiaCCC, who did not want to be named.

信息

难度
9
分类
(无)
标签
递交数
2
已通过
1
通过率
50%
上传者