情况:
给定一些带坐标(x,y)的点,范围0 <x <100,000,000和0 <y <100,000,000
我必须找到最小的正方形,其边缘和内部至少包含N个点.
我使用矢量来存储坐标并搜索所有正方形,边长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)对于我查找的每个方格,遍历完整的向量以查看其边缘和内部是否至少有N个点. …
我了解在什么情况下会调用哪个...
Sample a;
Sample b = a; //calls copy constructor
Sample c;
c = a; //calls assignment operator
Run Code Online (Sandbox Code Playgroud)
我的问题是,为什么这两种不同的东西都存在?为什么只有两者之一不能同时解决这两种情况?