码迷,mamicode.com
首页 > 其他好文 > 详细

[TC SRM 662 div1 lev1] FoxesOfTheRoundTable

时间:2017-02-18 17:05:21      阅读:200      评论:0      收藏:0      [点我收藏+]

标签:i+1   roo   sort   for   range   target   ted   lan   mda   

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

标签:i+1   roo   sort   for   range   target   ted   lan   mda   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!