【发布时间】:2017-10-28 18:13:45
【问题描述】:
我一直在解决这个问题,但我无法解决它。不知道从哪里开始,有人可以帮助我吗?
int below(Plot p, line l);
int above(Plot p, line l);
line findLine(Plot p, line l)
{
}
【问题讨论】:
-
@Amadeus.: 是的...我明白了
我一直在解决这个问题,但我无法解决它。不知道从哪里开始,有人可以帮助我吗?
int below(Plot p, line l);
int above(Plot p, line l);
line findLine(Plot p, line l)
{
}
【问题讨论】:
这是标准的二分查找问题。
线y = k 将绘图分成两等份(基于点数)。
y 的取值范围是多少?显然是-1 到+1。
是的,你可以。只需检查 Plot p 的每个点,然后检查其中有多少点的y 坐标大于k。你知道总点数,你就会知道直线两侧的点是否相等。
假设您选择了一行y=k。现在在这一点上,您会看到上面的点比下面的点多。现在你将向上移动。如果有更多的下行空间,那么您将向下移动。
double good = -1.0,bad= 1+EPSILON;
for(int iter=0;iter<=100;iter++)
{
mid = (good+bad)/2.0;
if(check(P,mid)) // if equally divides it then it's done
// mid is one answer;
else if( below(p,mid)<above(p,mid))
good=mid;
else
bad=mid;
}
【讨论】: