任何地方我有一個方形2dvector(網格),我要插入到它的零的數量(「濃」)。 然後,洗牌矢量以分發零。 (假設網格矢量大小爲10x10)。分發數量的零在網格
1)I嘗試:
int conc=1;
for (size_t i=0, max=conc; i!=max;i++){
grid.erase(grid.begin()+1);
for (size_t j=0,max=grid.size();j!=max; j++)
grid[i][j]=0;
}
random_shuffle(grid.begin(),grid.end());
的問題是,與上述我收到10個零(網格尺寸= 10×10)代替1-(現在濃度= 1,所以想要1爲零)。
和十個零點都在一個row.I想在網上的任何地方分配零的個數。
我想插入1個零(濃度)。
您可能想要閱讀['std :: random_shuffle'引用](http://en.cppreference.com/w/cpp/algorithm/random_shuffle)。 –
'的std :: random_shuffle'沒有返回 – P0W
@Joachim Pileborg:我查過,但在2D矢量我沒有管理,使其工作。 – George