比赛链接:2016 ICPC Mid-Central USA Region
题目链接:Windy Path
Description
Consider following along the path in the figure above, starting from $(4,4)$ and moving to $(2,5)$. Then the path turns rightward toward $(1,6)$, then sharp left to $(5,0)$ and finally sharp left again to $(4,2)$. If we use ‘$L$’ for left and ‘RR’ for right, we see that the sequence of turn directions is given by RLL
. Notice that the path does not cross itself: the only intersections of segments are the connection points along the path.
Consider the reverse problem: Given points in an arbitrary order,say $(2,5),(1,6),(4,4),(5,0),(4,2)$,could you find an ordering of the points so the turn directions along the path are given by RLL
? Of course to follow the path in the figure,you would start with the third point in the list $(4,4)$,then the first $(2,5)$,second $(1,6)$, fourth $(5,0)$, and fifth $(4,2)$, so the permutation of the points relative to the given initial order would be: $3 1 2 4 5$.