通过enum ObjectType { UNKNOWN = 0, UNKNOWN_MOVABLE = 1, UNKNOWN_UNMOVABLE = 2, PEDESTRIAN = 3, BICYCLE = 4, VEHICLE = 5, MAX_OBJECT_TYPE = 6 }; double dist[MAX_OBJECT_TYPE][MAX_OBJECT_TYPE] = { {0.2, 0.3, 0.4, 0.5, 0.6, 1}, {0.3, 0.2, 0.3, 0.4, 0.5, 0.6}, {0.4, 0.3, 0.2, 0.3, 0.4, 0.5}, {0.5, 0.4, 0.3, 0.2, 0.3, 0.4}, {0.6, 0.5, 0.3, 0.4, 0.2, 0.3}, {1 , 0.6, 0.5, 0.4, 0.3, 0.2} };表格随机选取所需横纵轴输出对应值
时间: 2023-08-19 07:28:23 浏览: 66
如果您想随机选取横轴和纵轴对应的值,可以使用随机数生成器来实现。以下是一个简单的使用C++的例子:
```c++
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
enum ObjectType {
UNKNOWN = 0,
UNKNOWN_MOVABLE = 1,
UNKNOWN_UNMOVABLE = 2,
PEDESTRIAN = 3,
BICYCLE = 4,
VEHICLE = 5,
MAX_OBJECT_TYPE = 6
};
double dist[MAX_OBJECT_TYPE][MAX_OBJECT_TYPE] = {
{0.2, 0.3, 0.4, 0.5, 0.6, 1},
{0.3, 0.2, 0.3, 0.4, 0.5, 0.6},
{0.4, 0.3, 0.2, 0.3, 0.4, 0.5},
{0.5, 0.4, 0.3, 0.2, 0.3, 0.4},
{0.6, 0.5, 0.3, 0.4, 0.2, 0.3},
{1 , 0.6, 0.5, 0.4, 0.3, 0.2}
};
int main() {
srand(time(NULL)); // 初始化随机数种子
int x = rand() % MAX_OBJECT_TYPE; // 随机生成横坐标
int y = rand() % MAX_OBJECT_TYPE; // 随机生成纵坐标
cout << "dist[" << x << "][" << y << "] = " << dist[x][y] << endl;
return 0;
}
```
在上述代码中,我们使用了`rand()`函数来生成0到`MAX_OBJECT_TYPE-1`之间的随机整数作为横坐标和纵坐标,然后输出对应的距离值。由于随机数生成器是基于时间种子的,故我们需要在程序一开始使用`srand()`函数来初始化随机数种子。
阅读全文