- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在编写一个程序来使用 graham scan 计算凸包的周长并且需要在一组数据点中找到最低的 y 坐标。我正在使用 std::min_element(vector.begin(), vector.end())
重载<
我结构中的运算符 point
.问题是有些点可能共享相同的最低 y 坐标,在这种情况下,我需要使用它们的 x 值来比较它们。是否有任何快速作弊来检查是否有任何其他点与 min_element 共享相同的 y 而不必遍历所有内容?
结构:
struct cord{
cord():x(0),y(0){}
int x,y;
bool operator<(const cord &p) const { return y < p.y; }
};
typedef std::vector<cord>::iterator vecIter;
函数调用:
vecIter lowestPoint =
std::min_element(points.begin(), points.end());
std::cout << "the lowest point of the data set is: " << "(" <<
lowestPoint->x << "," << lowestPoint->y << ")" << std::endl;
最佳答案
那么,就这样? (替换您现有的 operator<
函数)
bool operator<(const cord &p) const
{
if (y != p.y)
return y < p.y;
else
return x < p.x;
}
关于c++ - 如何让 min_element 捕获所有具有最低值的点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19408523/
非常基本的问题:如何找到随机矩阵中的最高值或最低值。我知道有可能说: a = find(A>0.5) 但我正在寻找的更像这样: A = rand(5,5) A = 0.9388 0.9498
我有这张表: BP1 BP2 ----------------------------- 140 80 153 8
我在这个网站上寻找与查找程序中最高/最低数据值有关的答案,但我发现的只是与数组有关的代码。我的代码中没有数组,因此我假设查找最高值或最低值的技术将以不同的方式执行。 如果您查看我的代码,您可以在输出的
这个问题不太可能帮助任何 future 的访问者;它只与一个小的地理区域、一个特定的时间点或一个非常狭窄的情况有关,这些情况并不普遍适用于互联网的全局受众。为了帮助使这个问题更广泛地适用,visit
我是一名优秀的程序员,十分优秀!