循环矩阵和向量

问题描述

我有一个带有2个元素a_destinations的向量,它们用两个整数表示源和目的地。 2 45 1 ...

我有一个矩阵test如下:

0 15 15 15 13 13 15 15 13 13 15 15 15 13 15 15 
2 1 2 2 2 2 2 2 2 2 10 2 2 2 10 2 
6 1 2 3 3 3 6 6 6 6 6 6 6 6 6 6 
7 2 2 3 4 4 2 7 7 7 7 7 7 7 7 7 
8 3 3 3 4 5 3 3 8 8 3 3 3 8 3 3 
9 4 4 4 4 5 4 4 4 9 4 4 4 9 4 4 
7 2 2 2 2 2 6 7 7 7 11 11 7 7 11 7 
12 6 6 3 3 3 6 7 8 8 12 12 12 12 12 12 
9 7 7 7 4 4 7 7 8 9 7 7 7 9 7 7 
13 8 8 8 8 5 8 8 8 9 13 13 13 13 13 13 
14 1 11 11 11 11 11 11 11 11 10 11 11 11 14 14 
12 6 6 12 12 12 6 12 12 12 10 11 12 12 10 12 
15 7 7 7 7 7 7 7 7 13 11 11 12 13 11 15 
0 12 12 12 9 9 12 12 9 9 12 12 12 13 12 12 
15 10 10 10 10 10 10 10 10 10 10 10 10 10 14 15 
0 12 12 12 12 12 12 12 12 12 14 12 12 12 14 15 

其中test[i][j]代表路径from i to j

每次test[i][j] != j,我们都会再次循环

示例:

从2到4的路径>> test[2][4] = 3test[3][4] = 4:我们输出:2、3、4

从1到7的路径>> test[1][7] = 2test[2][7] = 6 test[6][7] = 7:我们输出1、2、6、7

我尝试如下:

std::vector<vector<int>> test;
test = Graphe->P; // MATRIX IS FILLED like on top
vector< int > a_destinations; // Vector with the destinations: 2 4 or 5 10 or 1 4 ...

for ( unsigned i = 0; i < test.size(); i++){
    for (unsigned j = 0; j< test.size(); j++){
        for (unsigned k = 0; k < a_destinations->size() - 1 ; k ++){
             if ( a_destinations->at(k) == i && a_destinations->at(k+1) == j ){
                   if (test[i][j] == a_destinations->at(k+1)){
                        cout << a_destinations->at(k) << "," <<test[i][j];
                   } else {
                        cout << a_destinations->at(k) << "," << test[a_destinations->at(k)][j];
                   }
                        cout << "," << test[i][j];// << "," << a_destinations->at(k+1);

                        }
                }      
        }
}

但是我最终总是有2个目的地。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...