本文整理汇总了C++中vvi::push_back方法的典型用法代码示例。如果您正苦于以下问题:C++ vvi::push_back方法的具体用法?C++ vvi::push_back怎么用?C++ vvi::push_back使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vvi
的用法示例。
在下文中一共展示了vvi::push_back方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: construct
void construct() {
P.push_back(vi(n, 0));
compress();
vi occ(n + 1, 0), s1(n, 0), s2(n, 0);
for (int k = 1, cnt = 1; cnt / 2 < n; ++k, cnt *= 2) {
P.push_back(vi(n, 0));
for (int i = 0; i <= n; ++i) occ[i] = 0;
for (int i = 0; i < n; ++i)
occ[i+cnt<n?P[k-1][i+cnt]+1:0]++;
for (int i = 0, sum = 0, t; i <= n; ++i) {
t = occ[i];
occ[i] = sum;
sum += t;
}
for (int i = 0; i < n; ++i)
s1[occ[i+cnt<n?P[k-1][i+cnt]+1:0]++] = i;
for (int i = 0; i <= n; ++i) occ[i] = 0;
for (int i = 0; i < n; ++i)
occ[P[k-1][s1[i]]]++;
for (int i = 0, sum = 0, t; i <= n; ++i) {
t = occ[i];
occ[i] = sum;
sum += t;
}
for (int i = 0; i < n; ++i)
s2[occ[P[k-1][s1[i]]]++] = s1[i];
for (int i = 0, p1 = -3, p2 = -3; i < n; ++i) {
P[k][s2[i]] = (P[k-1][s2[i]] != p1 || (s2[i]+cnt<n?P[k-1][s2[i]+cnt]:-1) != p2) ? i : P[k][s2[i - 1]];
p1 = P[k-1][s2[i]];
p2 = s2[i]+cnt<n?P[k-1][s2[i]+cnt]:-1;
}
}
}
示例2: main
int main()
{
FILE *in = fopen (PROBLEM_NAME".in","r");
FILE *out = fopen (PROBLEM_NAME".out","w");
int k;
fscanf(in, "%d %d ", &n, &k);
for (int i = 0; i < n; ++i) {
used.push_back(false);
tin.push_back(0);
fup.push_back(0);
vi l;
g.push_back(l);
}
for (int i = 0; i < k; ++i) {
int x, y;
fscanf(in, "%d %d ", &x, &y);
g[x-1].push_back(y-1);
g[y-1].push_back(x-1);
}
timer = 0;
dfs(0);
sort(ans.begin(), ans.end());
ans.erase( unique( ans.begin(), ans.end() ), ans.end() );
fprintf(out, "%d\n", (int)ans.size());
for (size_t i = 0; i < ans.size(); ++i) {
fprintf(out, "%d\n", ans[i]+1);
}
fclose(in);
fclose(out);
return 0;
}
示例3: addTree
void addTree(int x, int y, int z) {
vi tree;
tree.push_back(x);
tree.push_back(y);
tree.push_back(z);
trees.push_back(tree);
}
示例4: main
int main()
{
ifstream fin ("graph2.txt"); //graph1.txt
for(int i=0;i<MAX;i++){
vi newVecG,newVecR;
graphG.push_back(newVecG);
graphR.push_back(newVecR);
}
int node1,node2;
while(fin>>node1>>node2){
//cout<<node1<<" "<<node2<<endl;
graphG[node1].push_back(node2);
graphR[node2].push_back(node1);
}
for(int i=0;i<MAX;i++){
if(visited[i]==false){
dfs(i);
}
}
cout<<"Reversed PostOrder of R"<<endl;
int SCCid=0;
while(!postOrder.empty()){
int node=postOrder.top();
postOrder.pop();
//cout<<node<<endl;
if(visited2[node]==false){
dfs_mark(node,SCCid);
SCCid++;
}
}
cout<<"Node\tSCCid"<<endl;
for(int i=0;i<MAX;i++){
cout<<i<<"\t"<<SCCids[i]<<endl;
}
return 0;
}
示例5: dfs
void dfs(int i, vi path, int left) {
if (left == 0) ans.push_back(path);
if (i == n) return ;
if (left >= candidate[i]) {
dfs (i + 1, path, left);
path.push_back(candidate[i]);
dfs(i, path, left - candidate[i]);
}
}
示例6: worker
void worker(vvi & ret, vi & temp, int level, vi & S) {
if(level == S.size()) {
ret.push_back(temp);
return;
}
worker(ret, temp, level + 1, S);
temp.push_back(S[level]);
worker(ret, temp, level + 1, S);
temp.pop_back();
}
示例7: construct
void construct() {
P.push_back(vi(n, 0));
compress();
vi occ(n + 1, 0), s1(n, 0), s2(n, 0);
for (int k = 1, cnt = 1; cnt / 2 < n; ++k, cnt *= 2) {
P.push_back(vi(n, 0));
fill(occ.begin(), occ.end(), 0);
for (int i = 0; i < n; ++i)
occ[i+cnt<n ? P[k-1][i+cnt]+1 : 0]++;
partial_sum(occ.begin(), occ.end(), occ.begin());
for (int i = n - 1; i >= 0; --i)
s1[--occ[i+cnt<n ? P[k-1][i+cnt]+1 : 0]] = i;
fill(occ.begin(), occ.end(), 0);
for (int i = 0; i < n; ++i)
occ[P[k-1][s1[i]]]++;
partial_sum(occ.begin(), occ.end(), occ.begin());
for (int i = n - 1; i >= 0; --i)
s2[--occ[P[k-1][s1[i]]]] = s1[i];
for (int i = 1; i < n; ++i) {
P[k][s2[i]] = same(s2[i], s2[i - 1], k, cnt)
? P[k][s2[i - 1]] : i;
}
}
}
示例8: dfs
//take n numbers out of nums for permu
//used[i]: ith number used
void dfs(const vi& nums, int n, vb& used, vi& cur, vvi& res) {
if (cur.size() == n){
res.push_back(cur);
return;
}
//try all numbers in nums
for (int i = 0; i < nums.size();++i) {
if (used[i]) continue;
used[i] = true;
cur.push_back(nums[i]);
dfs(nums,n,used,cur,res);
cur.pop_back();
used[i] = false;
}
}
示例9: fac
// calculate the factorial numbers
// general idea:
// https://blog.codechef.com/2009/07/02/tutorial-for-small-factorials/
// optimization: store all calculated numbers, calculate only when needed
void fac(vvi &f, size_t n) {
for (size_t highest = f.size(); highest < n; ++highest) {
vi current;
const int prev = highest-1;
int carry = 0;
for (vi::iterator it = f[prev].begin(); it != f[prev].end(); ++it) {
int next = *it * (highest+1) + carry;
carry = next / RANGE;
current.push_back(next % RANGE);
}
while (carry) {
current.push_back(carry % RANGE);
carry = carry / RANGE;
}
f.push_back(current);
}
}
示例10: dfs
void dfs(vvi& res, vi& cur, vpii& count, int idx) {
string ident(idx * 4, ' ');
if (idx == count.size()) {
res.push_back(cur);
return;
}
pii& p = count[idx];
int num = p.first, cnt = p.second;
for (int rep = 0; rep <= cnt; ++rep) {
for (int i = 0; i < rep; ++i) {
cur.push_back(num);
}
dfs(res, cur, count, idx + 1);
for (int i = 0; i < rep; ++i) {
cur.pop_back();
}
}
}
示例11: getMinimumInversions
int getMinimumInversions(vector<int> A, vector<int> B, vector<int> VArg, int KArg)
{
N = A.size();
K = KArg;
V = VArg;
for (int i = 0; i < N; ++i)
G.push_back(vi());
for (int i = 0; i < N; ++i) {
bool ok = true;
for (int j = 0; j < G[A[i]].size(); ++j) {
if (G[A[i]][j] == B[i]) {
ok = false;
break;
}
}
if (ok) {
G[A[i]].push_back(B[i]);
}
}
for (int i = 0; i < N; ++i) {
bool ok = true;
for (int j = 0; j < G[B[i]].size(); ++j) {
if (G[B[i]][j] == A[i]) {
ok = false;
break;
}
}
if (ok) {
G[B[i]].push_back(A[i]);
}
}
int ret = INT_MAX;
for (int i = 0; i < N; ++i) {
Bit bit(1001);
vb path(N);
ret = min(ret, dfs(i, path, 0, 0, bit));
}
return ret < INT_MAX ? ret : -1;
}
示例12: main
int main()
{
FILE *in = fopen (PROBLEM_NAME".in","r");
FILE *out = fopen (PROBLEM_NAME".out","w");
fscanf(in, "%d", &n);
for (int i = 0; i < n; ++i) {
tin.push_back(0);
tout.push_back(0);
used.push_back(false);
vi l;
g.push_back(l);
}
for (int i = 0; i < n; ++i) {
int p;
fscanf(in, "%d", &p);
if (p == 0) {
root = i;
} else {
g[p-1].push_back(i);
}
}
timer = 0;
dfs(root);
// print();
int k;
fscanf(in, "%d", &k);
for (int i = 0; i < k; ++i) {
int a, b;
fscanf(in, "%d %d", &a, &b);
int res = (upper(a-1, b-1)) ? 1 : 0;
fprintf(out, "%d\n", res);
}
fclose(in);
fclose(out);
return 0;
}
示例13: tarjanSCC
void tarjanSCC(int u) {
dfs_low[u] = dfs_num[u] = dfsNumberCounter++; // dfs_low[u] <= dfs_num[u]
S.push_back(u); // stores u in a vector based on order of visitation
visited[u] = 1;
for (int j = 0; j < (int)AdjList[u].size(); j++) {
ii v = AdjList[u][j];
if (dfs_num[v.first] == 0)
tarjanSCC(v.first);
if (visited[v.first])
dfs_low[u] = min(dfs_low[u], dfs_low[v.first]); }
if (dfs_low[u] == dfs_num[u]) { // if this is a root (start) of an SCC
scc.push_back(vi());
while (1) {
int v = S.back(); S.pop_back(); visited[v] = 0;
scc.back().push_back(v);
node_to_scc_num[v] = scc_num;
if (u == v) break; }
scc_num++;
}
}
示例14: visit
void visit (int i) {
nr[i] = low[i] = idx++;
S.push (i);
in_stack[i] = true;
for (vi::iterator it = gr[i].begin (); it != gr[i].end (); ++it) {
if (nr[*it] < 0) {
visit (*it);
low[i] = min (low[i], low[*it]);
} else if (in_stack[*it]) {
low[i] = min (low[i], low[*it]);
}
}
if (nr[i] == low[i]) {
int n;
vi comp;
do {
n = S.top (); S.pop ();
in_stack[n] = false;
comp.push_back (n);
} while (n != i);
sccs.push_back (comp);
}
}
示例15: main
int main(void){
ios::sync_with_stdio(false);
int x, y;
cin >> n >> m >> k;
for(int i = 1; i <= n; i += 1){
cin >> colors[i];
}
for(int i = 0; i < m; i += 1){
cin >> x >> y;
graph[x].push_back(y);
graph[y].push_back(x);
}
for(int i = 1; i <= n; i += 1){
//PRINT(visited, 7);
if(!visited[i]){
visited[i] = 1;
vi component;
component.push_back(i);
//cout << "pushing " << i << "to component" << endl;
dfs(i,component);
components.push_back(component);
}
}
// cout << "Size of component: " << components.size() << endl;
// for(vi& comp: components){
// for(int s: comp){
// cout << s << " ";
// }
// cout << endl;
// }
int ans = 0;
for(vi& component: components){
ans += maxcost(component);
}
cout << ans << endl;
}