CC's

Back

Liaoning ship, which named after a province of China, is the first aircraft carrier commissioned into the People’s Liberation Army Navy. It was bought from Ukraine as a stripped hulk and was rebuilt by China as an important part of China’s blue water Navy plan. Liaoning ship has sailed far into the Pacific Ocean for serval times, which shows the power and resolve of China to defend her integrity of territory.

Now Liaoning ship is on a new voyage to the Atlantic Ocean for a maneuver! The vast maneuver region on the ocean can be seen as an n×n grid which has n×n crosspoints. Each crosspoint stands for a check point of the maneuver region. Liaoning starts from the bottom-left check point whose coordinate is (0,0), and its destination is the upper-right checkpoint whose coordinate is (n-1,n-1). The positive side of the x axis points to the right, and the positive side of the y axis points up. All check points’ coordinates are integral. During each move, Liaoning can go from one check point to its adjacent 8 check points along a straight line, and each move takes Liaoning one day. Some check points are not available to go due to the bad weather. And, as you know, on the Atlantic Ocean, there is a Bermuda Triangle in which many ships and planes were missing. Liaoning can’t take risk to go into that triangle. Of course, Liaoning can’t go outside the maneuver region. Please figure out a route for Liaoning to reach its destination as soon as possible.

分析#

实际上本体是个Dijkstra,但是两点是否相连需要使用到计算几何的东西。重点就在于如何判断行进过程是否穿过了百慕大三角。

然后就WA了8发。

实际判断时会有很多问题。例如从边上经过,从外界到边,从边到边,从边到外界,从外界到点,从点到外界,从边穿过点……如果一开始选择的判断方法有锅的话,之后就改不出来了,只能WA……

最终想出来的解决办法是拿到行进线段与三角形三边的交点,连接交点构造新线段后,判断线段中点是否在三角形内;并同时判断起点终点是否在三角形内。这样就能避免掉复杂的讨论。

其次,顺便把已经在三角形内的整点全部标记了不能访问。

这样就过了。

代码#

板子判点在线段部分有问题,要改。

Liaoning Ship’s Voyage
https://astro-pure.js.org/blog/liaoning-ships-voyage
Author Cheng Chen
Published at 2019年10月27日
Comment seems to stuck. Try to refresh?✨