本文整理汇总了C++中QuadTree::query方法的典型用法代码示例。如果您正苦于以下问题:C++ QuadTree::query方法的具体用法?C++ QuadTree::query怎么用?C++ QuadTree::query使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QuadTree
的用法示例。
在下文中一共展示了QuadTree::query方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GLrender
void GLrender()
{
glClear(GL_COLOR_BUFFER_BIT);
lines = quadtree.query(Point2D(me.c.p.x,me.c.p.y),me.c);
quadtree.render();
me.c.render(col);
glFlush();
glutSwapBuffers();
}
示例2: main
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
QuadTree<100000, 4000100> qt;
int N, Q;
cin >> N >> Q >> ws;
vector<string> inp(N, "");
Node *ft = new Node(), *bt = new Node();
for (int i = 0; i < N; ++i) {
getline(cin, inp[i]);
ft->insert(inp[i]);
bt->rinsert(inp[i], inp[i].length() - 1);
}
int fc = 0, bc = 0;
ft->leaf_fix(fc);
bt->leaf_fix(bc);
vii lr(N, {-1, -1});
for (int i = 0; i < N; ++i) {
lr[i].first = ft->getleaf(inp[i], 0).first;
lr[i].second = bt->getleaf_r(inp[i], inp[i].length()-1).first;
// cerr << i << ' ' << lr[i].first << ' '<<lr[i].second << endl;
}
vii bysize;
for (int i = 0; i < N; ++i) bysize.push_back({inp[i].size(), i});
sort(bysize.rbegin(), bysize.rend());
inp.clear();
vector<string> query(Q, "");
vii qbysize;
for (int q = 0; q < Q; ++q) {
getline(cin, query[q]);
qbysize.push_back({query[q].size(), q});
}
sort(qbysize.rbegin(), qbysize.rend());
vi ans(Q, 0LL);
// Handle queries one by one
for (int _q = 0, i = 0; _q < Q; ++_q) {
int q = qbysize[_q].second;
// Insert all strings that are strictly smaller
while (i < N && bysize[i].first + 1 >= qbysize[_q].first) {
int s = bysize[i].second;
qt.insert(lr[s], 1);
++i;
}
// Process the query
ii prefr = ft->getleaf_ast(query[q], 0);
ii suffr = bt->getleaf_rast(query[q], query[q].length()-1);
if (prefr.second == -1 || suffr.second == -1) continue;
// cerr << q << " ";
// cerr << prefr.first << ' ' <<prefr.second << " ";
// cerr << suffr.first << ' ' <<suffr.second << endl;
--prefr.second;
--suffr.second;
ans[q] = qt.query(prefr.first, suffr.first, prefr.second, suffr.second);
}
for (size_t i = 0; i < ans.size(); ++i) cout << ans[i] << '\n';
return 0;
}