今天无意中发现一道算法题很有意思,题不难,都是初中的知识,主要就是求一个固定点到一条直线的最短距离,我用了一个非常麻烦的方法才求出,我先是用余弦定理求出夹角再判断用勾股定理结合方程组解出来,很是麻烦,还画了几张图,我就问我以为朋友,他说很简单啊,拿线上两点就求出来了线的斜率然后结合点到直线距离公式就出来了。
可能我描述的不是很清楚,先来看一下题:
Brio got his house constructed near the National Highway. The Construction and Planning Committee has planned to construct a road near his house. Brio is worried about the Committee's plan as he fears that his house might come on the way of the road being constructed. In such a case, he needs to request the Committee members to replan the construction. Assume that Brio's house is a circle with center at (0,0) and radius r. Given 2 integral points (x1,y1) and (x2,y2) through which the road passes you need to give output as