int main() { srand(time(NULL)); scanf("%d", &n); for(int i=1; i<=n; i++) a[i] = rand(); long long ans6 = ndp(); printf("O(n) DP : %lld\n", ans6); long long ans5 = ngreedy(); printf("O(n) greedy : %lld\n", ans5); long long ans4 = n1(); printf("n : %lld\n", ans4); long long ans3 = nlogn(1, n+1); printf("nlogn : %lld\n", ans3); long long ans2 = n2(); printf("n^2 : %lld\n", ans2); long long ans1 = n3(); printf("n^3 : %lld\n", ans1); assert(ans1 == ans2 && ans2 == ans3 && ans3 == ans4 && ans4 == ans5); system("pause"); return 0; }
void ParseTreeLablerForm::selectionChangedSlot(const QItemSelection & /*newSelection*/, const QItemSelection & /*oldSelection*/) { //get the text of the selected item const QModelIndex index = widget.treeView->selectionModel()->currentIndex(); QString selectedText = index.data(Qt::DisplayRole).toString(); string name = getCppString(selectedText); QStandardItem *parNode = nameToTreeNode[name]; int numChildren = parNode->rowCount(); segNumToColor.clear(); Node nd(name); if (nd.type == "Terminal") { segNumToColor[nd.id] = randColor(); } colorMapTableModel->clearAll(); for (int i = 0; i < numChildren; i++) { QStandardItem *child = parNode->child(i, 0); queue<QStandardItem *> bfsQueue; float color = randColor(); ColorRGB colorRGB(color); colorMapTableModel->addItem(getCppString(child->text()),QColor(colorRGB.r*255,colorRGB.g*255,colorRGB.b*255)); bfsQueue.push(child); //boost::random::uniform_int_distribution<> randSix(0,5); // distribution that maps to 1..6 // see random number distributions while (!bfsQueue.empty()) { QStandardItem *curNode = bfsQueue.front(); bfsQueue.pop(); int numChildren = curNode->rowCount(); string parName = getCppString(curNode->text()); //cout << "selseg:" << parName.substr(0, 10) << endl; //cout << "selseg:" << "Terminal__" << endl; Node ndp(parName); if (ndp.type == "Terminal") { segNumToColor[ndp.id] = color; continue; } //cout << parName << endl; for (int i = 0; i < numChildren; i++) { QStandardItem *child = curNode->child(i, 0); // cout << "child:" << getCppString(child->text()) << endl; bfsQueue.push(child); } } } colorSegs(segNumToColor, true); updatePCDVis(); }