小编Nig*_*rry的帖子

用于稀疏数据查找的高效数据结构

情况:

给定一些带坐标(x,y)的点,范围0 <x <100,000,000和0 <y <100,000,000

我必须找到最小的正方形,其边缘和内部至少包含N个点.

  1. 我使用矢量来存储坐标并搜索所有正方形,边长minLength到边长maxLength(在相关空间中施加蛮力)

    struct Point
    {
            int x;
            int y;
    };
    
    vector<Point> P;
    int minLength = sqrt(N) - 1;
    int maxLength = 0;
    
    //   bigx= largest x coordinate of any point
    //   bigy= largest y coordinate of any point
    //   smallx= smallest x coordinate of any point
    //   smally= smallest y coordinate of any point
    
    (bigx - smallx) < (bigy - smally) ? maxLength = (bigx - smallx) : maxLength = (bigy - smally);
    
    Run Code Online (Sandbox Code Playgroud)
  2. 对于我查找的每个方格,遍历完整的向量以查看其边缘和内部是否至少有N个点. …

c++ algorithm

10
推荐指数
1
解决办法
427
查看次数

为什么不只有一个?复制构造函数和赋值运算符

我了解在什么情况下会调用哪个...

Sample a;
Sample b = a; //calls copy constructor
Sample c;
c = a;        //calls assignment operator
Run Code Online (Sandbox Code Playgroud)

我的问题是,为什么这两种不同的东西都存在?为什么只有两者之一不能同时解决这两种情况?

c++ copy-constructor copy-assignment

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