public: QVector<QVector<Point>> ResultVector; QVector<Point> leftAN; QVector<Point> rightAN; QVector<Point> boatList; QVector<Point> result;//储存最终路径 //输出 void test() { for (int i = 0; i < ResultVector.size();i++) { result = ResultVector[i]; if (result.size() > 0) { for (int i = 0; i < result.size(); i++) { qDebug() << "(" << result[i].x << "," << result[i].y << "," << result[i].z << ") "; } //cout << endl; } else { qDebug() << "找不到结果"; } } } void getFirst() //获取最优解,用于演示 { int i = 0; result = ResultVector[0]; for(i = 0;i<result.size()-1;i++) { Point lp,rp; Point bp; lp.x = result[i].x; lp.y = result[i].y; rp.x = abs(result[0].x - result[i+1].x); rp.y = abs(result[0].y - result[i+1].y); bp.x = abs(result[i].x - result[i+1].x); bp.y = abs(result[i].y - result[i+1].y); bp.z = result[i].z; leftAN.push_back(lp); rightAN.push_back(rp); boatList.push_back(bp); } }
时间: 2023-06-26 21:05:14 浏览: 44
这段代码看起来是一个船过河问题的解决方案。其中,ResultVector 储存了所有可能的路径,result 储存了当前正在处理的路径,leftAN、rightAN 和 boatList 则分别储存了每个路径中左岸、右岸和船上的人数和狼/羊/菜的情况。
test() 函数用于输出所有的路径和最终结果,而 getFirst() 函数则用于获取最优解并存储相关信息以便演示。
相关问题
std::vector<cv::Point>转换为QVector<QPoint>
可以以下代码将`std::vector<cv::Point>`转换为`QVector<QPoint>`:
```c++
#include <QVector>
#include <QPoint>
#include <vector>
#include <opencv2/core/core.hpp>
QVector<QPoint> vectorCvPointToQPoint(const std::vector<cv::Point>& points) {
QVector<QPoint> qPoints;
for (const cv::Point& point : points) {
qPoints.append(QPoint(point.x, point.y));
}
return qPoints;
}
```
您可以通过调用 `vectorCvPointToQPoint` 函数并传入 `std::vector<cv::Point>` 类型的数据来获得 `QVector<QPoint>` 类型的数据。
std::vectorcv::Point转换为QVector<QVector<QPoint>>
将`std::vector<cv::Point>`转换为`QVector<QVector<QPoint>>`的方法如下:
```c++
#include <QVector>
#include <QPoint>
#include <vector>
#include <opencv2/core/core.hpp>
QVector<QVector<QPoint>> vectorCvPointToQVectorQPoint(const std::vector<cv::Point>& points) {
QVector<QVector<QPoint>> qVectors;
QVector<QPoint> qPoints;
for (const cv::Point& point : points) {
qPoints.append(QPoint(point.x, point.y));
}
qVectors.append(qPoints);
return qVectors;
}
```
您可以通过调用 `vectorCvPointToQVectorQPoint` 函数并传入 `std::vector<cv::Point>` 类型的数据来获得`QVector<QVector<QPoint>>`类型的数据。函数将每个`cv::Point`转换为`QPoint`并将其添加到`QVector<QPoint>`中,然后将每个`QVector<QPoint>`添加到`QVector<QVector<QPoint>>`中。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![png](https://img-home.csdnimg.cn/images/20210720083516.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)