Timus #1444

题目说明:二维数组上有一些点,以第一个点为起点,把剩下的点连起来形成一个没有边相交的多边形,类似于一笔画,无需回到起点,只需把n个点连起来。

题目解析:类似于Timus #1607,极角排序,但排序顺序难想很多。首先找到x轴最小的点作为算法中整个图形的起点。计算每个点的atan2。对atan2进行升序排序,但是其中atan2角度可能相同,你可以画画图想想一下,对相同的距离也进行进行升序排序,距离越大连的越后面。但是我们这道题起点必须为输入的第一个点,这就意味着我们取x轴最小的点作为起的时候需要收尾也要相连,所以如果有大于两个的点位于x轴最小的点的正上方,就会出现收尾不可能相连的错误,这就需要对距离进行降序排序。具体sort函数排序方法可见代码f函数

Problem analysis English version:

  • Find the point with minimum x, exchange it to the first position.
  • Cal atan2.
  • Sort atan2 exclude the point with minimum x which is in the first position.  
  • Find the index which is 1 and output the result.

Difference of sort definition between problem 1207:
Increasing order by theta. When theta is same, use increasing order of the distance from min_x point besides one situation. However if the points have same theta and is directly above the min_x point , we must use descending order of the distance from min_x point.

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

浙ICP备2021019730-1    浙公网安备 33010902002953号
Copyright © 2024 PanCake