Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/algorithm/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何使min_元素捕获具有最小值的所有点?_C++_Algorithm_Grahams Scan - Fatal编程技术网

C++ 如何使min_元素捕获具有最小值的所有点?

C++ 如何使min_元素捕获具有最小值的所有点?,c++,algorithm,grahams-scan,C++,Algorithm,Grahams Scan,我正在写一个程序来计算凸包的周长,需要在一组数据点中找到最低的y坐标。我正在使用std::min_元素(vector.begin(),vector.end())和一个重载的那么,像这样吗?(要替换现有的操作符或只需更改操作符如果您与cord对象类结为夫妻,请在操作符中使用。您是否试图为最小的y找到最小的x,或者用最小的y找到所有点?您的标题指向后者,但您的问题是b。)奥迪指出了前者。 struct cord{ cord():x(0),y(0){} int x,y;

我正在写一个程序来计算凸包的周长,需要在一组数据点中找到最低的y坐标。我正在使用
std::min_元素(vector.begin(),vector.end())
和一个重载的
那么,像这样吗?(要替换现有的
操作符或只需更改
操作符如果您与
cord
对象类结为夫妻,请在
操作符中使用。您是否试图为最小的
y
找到最小的
x
,或者用最小的
y
找到所有点?您的标题指向后者,但您的问题是b。)奥迪指出了前者。
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;
bool operator<(const cord &p) const
{
   if (y != p.y)
     return y < p.y;
   else
     return x < p.x;
}