首页 > 其他 > 详细

[TC SRM 662 div1 lev1] FoxesOfTheRoundTable

时间:2017-02-18 17:04:32      阅读:172      评论:0      收藏:0      [点我收藏+]

转载: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.

[TC SRM 662 div1 lev1] FoxesOfTheRoundTable

原文:http://www.cnblogs.com/ivancjw/p/6413340.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!