我試圖將一個變量(1 - 100 000)長度矢量分成隨機部分進一步操作。但是我的代碼崩潰了,到目前爲止,我的調試沒有結果。誰能提供任何見解?試圖Subvectorize矢量的隨機[1-100 000]長度
#include <math.h>
#include <vector>
#include <iostream>
using namespace std;
void subVectorize() {
//N ways to pick consecutive integer sequences of length M (M < N) K-Vlaue is Kth smallest number in sequence
//Task: Find smallest possible subsequence
int M = rand() % (100000 - 1);
vector<int> nVector(M); //Vector to store sequence of variable length
for (int i = 0; i < nVector.size(); i++) //Populate the vector
{
nVector[i] = i;
}
//Split the vector randomly
vector<int>::const_iterator start = nVector.begin() + (rand() % (100000 - 1));
vector<int>::const_iterator end = nVector.begin() + (rand() % (100000 - 1));
vector<int> subVector(start, end);
}
你'start'可以end'後'而且兩者可以同時出的範圍。 – 2014-10-18 01:43:19
剛剛發現並應用了一個修復程序 - 我想!仍試圖找出隨機性;我想我需要種下它?沒有時間庫,有沒有辦法做到這一點? – 2014-10-18 01:56:02
如果我能夠幫助你,請通過接受我的回答告訴我,或者更新你的問題。此外,如果您找到可能不同的解決方案,包括它可以幫助其他人找到解決問題的正確解決方案。 – deW1 2014-10-28 21:57:46