本文整理汇总了C++中vvi类的典型用法代码示例。如果您正苦于以下问题:C++ vvi类的具体用法?C++ vvi怎么用?C++ vvi使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了vvi类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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);
}
}
示例2: mat_pow
vvi mat_pow(vvi a,int n) {
vvi ret;
for(int i=0;i<a.size();i++) {
vector<int> v(a.size(),0);
v[i]=1;
ret.push_back(v);
}
while(n>0) {
if(n%2==1)
ret=mul(ret,a);
a=mul(a,a);
n/=2;
}
return ret;
}
示例3: mul
vvi mul(vvi a, vvi b) {
vvi ret;
for(int i=0;i<a.size();i++) {
vector<int> v;
for(int j=0;j<a[i].size();j++) {
lli val=0;
for(int k=0;k<b.size();k++) {
val+=(lli)a[i][k]*(lli)b[k][j];
val%=mod;
}
v.push_back((int)val);
}
ret.push_back(v);
}
return ret;
}
示例4: centroid_decomposition
centroid_decomposition( const vvi& graph ) {
N = sz(graph);
centroid_graph.resize(N);
parent.assign(N, -1);
node_mapping.assign(N, -1);
subtree_size.assign(N, 0);
decompose(0, -1, graph);
reverse_mapping.assign(N, -1);
for(int i = 0; i < N; ++i) reverse_mapping[ node_mapping[i] ] = i;
}
示例5: 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();
}
示例6: showgraph
void showgraph(vvi& g)
{
for(int i=0;i<g.size();i++)
{
cout<<(i+1)<<" : ";
for(int j=0;j<g[i].size();j++)
cout<<g[i][j]+1<<" ";
cout<<endl;
}
}
示例7: flip
void flip(vvi& g, vvi& revg)
{
for(int i=0;i<g.size();i++)
{
for(int j=0;j<g[i].size();j++)
{
revg[g[i][j]].push_back(i);
}
}
}
示例8: 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;
}
示例9: main
int main()
{
int t;
scanf("%d",&t);
for(int i=0;i<t;++i)
{
scanf("%d %d",&h,&w);
stones.clear();
stones.insert(stones.begin(),h,vi(w,0));
for(int i=0;i<h;++i)
for(int j=0;j<w;++j)
scanf("%d",&stones[i][j]);
cout<< optimal() <<endl;
}
return 0;
}
示例10: 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);
}
示例11: main
int main() {
// freopen("in.txt", "r", stdin);
scanf("%d", &n);
adj.resize(n + 5);
g.resize(n + 5);
for (int i = 1; i <= n; i++) {
string l;
cin >> l;
if (loc.find(l) == loc.end())
loc[l] = top++;
location[i] = loc[l];
int m;
scanf("%d", &m);
for (int j = 0; j < m; j++) {
int v;
scanf("%d", &v);
// adj[i].push_back(v);
adj[v].push_back(i);
}
adj[i].push_back(i);
}
for (int i = 1; i <= n; i++) {
for (int j = 0; j < sz(adj[i]); j++) {
for (int k = j + 1; k < sz(adj[i]); k++) {
int u = adj[i][j];
int v = adj[i][k];
if (location[u] != location[v]) {
g[u].push_back(v);
g[v].push_back(u);
}
}
}
}
clr(vis, -1);
for (int i = 1; i <= n; i++)
if (vis[i] == -1)
bfs(i);
if (sz(ans) == 0)
ans.push_back(1);
printf("%d\n", sz(ans));
for (int i = 0; i < sz(ans); i++)
printf("%d ", ans[i]);
return 0;
}
示例12: 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]);
}
}
示例13: solve
int solve(){
int maxLen = 0;
for( int i = 0; i < map.size(); i++ ){
for( int j = 0; j < map[i].size(); j++ ){
//printf("%3d", dp(i, j));
if( maxLen < dp(i, j) ) maxLen = dp(i, j);
}
}
return maxLen + 1;
}
示例14: initRules
void initRules()
{
rulesDirection.resize(4);
for(int i=0; i<4; ++i)
rulesDirection[i].resize(4);
//First index : ball, second : goal
rulesDirection[LEFT][LEFT] = LEFT;
rulesDirection[LEFT][FRONT] = LEFT;
rulesDirection[LEFT][RIGHT] = LEFT;
rulesDirection[LEFT][BACK] = LEFT;
rulesDirection[FRONT][LEFT] = RIGHT;
rulesDirection[FRONT][FRONT] = FRONT;
rulesDirection[FRONT][RIGHT] = LEFT;
rulesDirection[FRONT][BACK] = LEFT;
rulesDirection[RIGHT][LEFT] = RIGHT;
rulesDirection[RIGHT][FRONT] = RIGHT;
rulesDirection[RIGHT][RIGHT] = RIGHT;
rulesDirection[RIGHT][BACK] = RIGHT;
rulesDirection[BACK][LEFT] = RIGHT;
rulesDirection[BACK][FRONT] = RIGHT;
rulesDirection[BACK][RIGHT] = LEFT;
rulesDirection[BACK][BACK] = RIGHT;
rulesSpeed.resize(3);
for(int i=0; i<3; ++i)
rulesSpeed[i].resize(3);
rulesSpeed[CLOSE][CLOSE] = SLOW;
rulesSpeed[CLOSE][AVG_DIST] = SLOW;
rulesSpeed[CLOSE][FAR] = SLOW;
rulesSpeed[AVG_DIST][CLOSE] = SLOW;
rulesSpeed[AVG_DIST][AVG_DIST] = AVG_SPEED;
rulesSpeed[AVG_DIST][FAR] = AVG_SPEED;
rulesSpeed[FAR][CLOSE] = FAST;
rulesSpeed[FAR][AVG_DIST] = AVG_SPEED;
rulesSpeed[FAR][FAR] = FAST;
}
示例15: main
int main(){
int n;
cin>>n;
vi t;
t.resize(n,-1);
dp.resize(n,t); // dp is n X n
for(int i=0;i<n;i++){
int r,c;
cin>>r>>c;
vi temp;
temp.pb(r);
temp.pb(c);
matrices.pb(temp);
}
cout<<solve(0,n-1)<<endl;
int A;
cin>>A;
return 0;
}