小编sam*_*mmy的帖子

减少查找 N 线交点所需的时间

N条线段,它们要么是水平的,要么是垂直的。现在我需要找出每条线段的交点总数和交点总数。N可以达到100000。我试着检查每一对线。答案是正确的,但我需要减少它所花费的时间。

这是我的代码:

using namespace std;

typedef struct Point
{
     long long int x;
     long long int y;
} ;


bool fun(Point p0, Point p1, Point p2, Point p3)
{
    double s1_x, s1_y, s2_x, s2_y;
    s1_x = p1.x - p0.x;     s1_y = p1.y - p0.y;
    s2_x = p3.x - p2.x;     s2_y = p3.y - p2.y;

    double s, t;
    s = (-s1_y * (p0.x - p2.x) + s1_x * (p0.y - p2.y)) / (-s2_x * s1_y …
Run Code Online (Sandbox Code Playgroud)

c++ algorithm time-complexity line-intersection

5
推荐指数
1
解决办法
1154
查看次数