本文整理汇总了C++中vi::reserve方法的典型用法代码示例。如果您正苦于以下问题:C++ vi::reserve方法的具体用法?C++ vi::reserve怎么用?C++ vi::reserve使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vi
的用法示例。
在下文中一共展示了vi::reserve方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: generate
void generate(const int &n, int **adjacencyMatrix) {
population.reserve(population_size);
new_population.reserve(population_size);
tmp.reserve(n);
tmp.clear();
REP(i,n) tmp.push_back(i);
REP(i,population_size) {
population.push_back(make_pair(tmp,calculate(tmp,n,adjacencyMatrix)));
random_shuffle(population[i].first.begin(), population[i].first.end());
}
示例2: main
int main()
{
ios_base :: sync_with_stdio(0);
cin.tie(0);
dist.reserve(505);
while(scanf("%d %d %d", &n, &m, &q) != EOF)
{
for (int i = 0 ; i < n ;i++)
{
scanf("%d", &idade[i]);
}
v.assign(n, vi());
for (int i = 0 ; i < m; i++)
{
scanf("%d %d", &s, &d);
--s; --d;
v[d].push_back(s);
}
for (int i = 0 ; i < q; i++)
{
getchar();
scanf("%c %d", &c, &s);
--s;
if (c == 'P')
{
queue<int> q;
dist.clear();
for (int i = 0 ; i < n ; i++) dist[i] = INF;
dist[s] = 0;
q.push(s);
int mn = INF;
while (!q.empty())
{
int u = q.front();
q.pop();
for (int i = 0 ; i < v[u].size(); i++)
{
int aux = v[u][i];
if (dist[aux] > dist[u] + 1)
{
dist[aux] = dist[u] + 1;
mn = min(mn, idade[aux]);
q.push(aux);
}
}
}
if (mn == INF) printf("*\n");
else printf("%d\n", mn);
}
else
{
scanf("%d", &d);
--d;
for (int i = 0 ; i < n; i++)
{
for (int j = 0; j < v[i].size(); j++)
{
if (v[i][j] == s)
v[i][j] = d;
else if (v[i][j] == d)
v[i][j] = s;
}
}
vi aux = v[s];
v[s] = v[d];
v[d] = aux;
}
}
v.clear();
}
}