提供以下代码:
#include <iostream>
#include <bitset>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef pair<int, int> coordinate;
typedef vector<coordinate> path;
class Game {
private:
vector<bitset<15>> board{15};
vector<path> paths;
public:
Game() {
for (int i = 0; i < 15; i++) {
string line;
getline(cin, line);
for (int j = 0; j < 15; j++) {
if (line[j] == '.') {
board[i].set(j); // the problem no longer occurs after removing this line
if (paths.size() > 2)
cout << "A: " << paths[2].back().first << endl;
paths.emplace_back(1, make_pair(j, i));
if (paths.size() > 2)
cout << "B: " << paths[2].back().first << endl;
}
}
}
}
};
int main() {
Game game;
return 0;
}
我遇到了问题,向量paths中的值被行[[board [i] .set(j);)更改。在我看来,这两个向量完全无关。给定以下输入(此问题发生在多个输入中,这只是我测试的一个):
.........xx....
..xx.....xx....
..xx...........
...............
...............
.........xx....
....xx...xx....
....xx.........
...............
...xx..xx......
...xx..xx......
...............
...............
............xx.
............xx.
此输入产生以下输出:
A: 2 B: 2 A: 2 B: 2 ... A: 2 B: 2 A: 3 B: 3 A: 3 B: 3 A: 7 B: 7 A: 15 B: 15 A: 31 B: 31 A: 63 B: 63 A: 127 B: 127 A: 255 B: 255 A: 511 B: 511 A: 1023 B: 1023 A: 2047 B: 2047 A: 4095 B: 4095 A: 8191 B: 8191 A: 16383 B: 16383 A: 32767 B: 32767 ... A: 32767 B: 32767 A: 32767 B: 32767
我尝试过的一件事是将更改为board [i] | = 1 << j;,但这无效。我无法弄清楚这些值的更改方式或解决方法,在此先感谢您的时间和帮助。board [i] .set(j);