本文整理汇总了C++中vc::resize方法的典型用法代码示例。如果您正苦于以下问题:C++ vc::resize方法的具体用法?C++ vc::resize怎么用?C++ vc::resize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vc
的用法示例。
在下文中一共展示了vc::resize方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main ()
{
srand (time (0));
freopen (NAME".in", "r", stdin);
freopen (NAME".out", "w", stdout);
scanf ("%d %d", &n, &m);
g.resize (n + 1);
used.resize (n + 1, 0);
for (int i = 0; i < m; i++)
{
int x, y;
scanf ("%d %d", &x, &y);
g [x].pb (y);
g [y].pb (x);
}
int ans = 0;
for (int i = 1; i <= n; i++)
if (!used [i])
{
ans++;
dfs (i);
}
printf ("%d\n", ans);
return 0;
}
示例2: main
int main ()
{
srand (time (0));
freopen (NAME".in", "r", stdin);
freopen (NAME".out", "w", stdout);
scanf ("%d", &n);
primes.resize (n + 1, 1);
primes [0] = primes [1] = 0;
for (int i = 2; i * i <= n; i++)
if (primes [i] && (i * 1ll * i <= n))
for (int j = i * i; j <= n; j += i)
primes [j] = 0;
int ans = 0;
int res = 2;
for (int i = 1; i <= n; i++)
{
ans += primes [i];
res = primes [i] ? i : res;
}
cout << ans << endl;
cout << res << endl;
return 0;
}
示例3: main
int main ()
{
srand (time (0));
freopen ("input.txt", "r", stdin);
freopen ("output.txt", "w", stdout);
scanf ("%d %d", &n, &m);
g.resize (n + 1);
used.resize (n + 1, 0);
for (int i = 0; i < m; i++)
{
int x, y;
scanf ("%d %d", &x, &y);
g [x].pb (y);
num [x][y] = i + 1;
}
int st;
scanf ("%d", &st);
vi ans;
found = 0;
dfs (st, ans);
if ((int) ans.size () == 0)
{
puts ("-1");
return 0;
}
reverse (ans.begin (), ans.end ());
ans.pop_back ();
printf ("%d\n", (int) ans.size ());
for (int i = 0; i < (int) ans.size (); i++)
printf ("%d%c", ans [i], " \n" [i == (int) ans.size () - 1]);
return 0;
}