转载:http://codeforces.com/blog/entry/19151
Note: 将问题转化为寻找hamiltonian回路问题。证明过程值得一看。
Suppose the heights are sorted: h[0] <= h[1] <= h[2] ...
In one hand, we know the answer can‘t be smaller than max{x[i+2] — x[i]}. We can proof this in the following way: If abs(x[i]-x[j]) >= ans, we add an edge between i and j. We assume there is an i and ans < x[i+2]-x[i]. Then if the graph is connected, edges (i, i+1) and (i+1, i+2) will be bridege (since if x < i and y > i+2 then there is no edge between x and y.) It means this graph don‘t have a hamiltonian cycle, so we can‘t arrange these foxes around a round table.
In another hand, we know that we have a solution that ans = max{x[i+2]-x[i]}: x[0]-x[2]-x[4]-x[6]-...-n-...x[5]-x[3]-x[1]-x[0].
So we know this solution is optimal.