本文整理汇总了C++中vvi类的典型用法代码示例。如果您正苦于以下问题:C++ vvi类的具体用法?C++ vvi怎么用?C++ vvi使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了vvi类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
}
开发者ID:stephanseebacher,项目名称:codechef,代码行数:21,代码来源:FCTRL2.cpp
示例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;
}
开发者ID:saikrishna17394,项目名称:Code,代码行数:17,代码来源:ktour.cpp
示例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;
}
开发者ID:saikrishna17394,项目名称:Code,代码行数:18,代码来源:ktour.cpp
示例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;
}
开发者ID:FranciscoThiesen,项目名称:CompetitiveProgramming,代码行数:10,代码来源:QTREE4.cpp
示例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();
}
开发者ID:seuzl,项目名称:myleetcode,代码行数:10,代码来源:subsets.cpp
示例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;
}
}
开发者ID:abusomani,项目名称:UVA,代码行数:10,代码来源:11504(scc).cpp
示例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);
}
}
}
开发者ID:abusomani,项目名称:UVA,代码行数:10,代码来源:11504(scc).cpp
示例8: find_sccs
vvi find_sccs(const vvi& adj_list) {
// Reset
num_scc = ticks = 0;
s = stack<int>();
d = vi(adj_list.size(), UNEXPLORED);
low = vi(adj_list.size());
scc = vi(adj_list.size(), NO_SCC);
in_stack = vector<bool>(adj_list.size(), false);
// DFS all nodes
for (int a = 0; a < adj_list.size(); ++a) {
if (d[a] == UNEXPLORED) tarjan(adj_list, a);
}
// Count which scc every node belong to
vvi sccs(num_scc);
for (int i = 0; i < scc.size(); ++i) {
sccs[scc[i]].push_back(i);
}
return sccs;
}
开发者ID:drathier,项目名称:compprogcheatsheet,代码行数:21,代码来源:tarjan.cpp
示例9: print
void print (const vvi& s) {
int N = s.size();
for (int i=0; i<N; i++)
{
for (int j=0; j<N; j++)
{
printf ("%c", s[i][j]);
}
printf ("\n");
}
printf("\n");
}
开发者ID:yongduek,项目名称:usaco,代码行数:12,代码来源:milk.cpp
示例10: aho_corasick
void aho_corasick(string &sentence, vector<string> &words,vvi &matches){
matches.assign(sentence.length(), vi());
int state = 0, ss = 0;
for (int i = 0; i < sentence.length(); ++i, ss = state) {
while (a[ss].child[mp(sentence[i])] == -1)
ss = a[ss].failure;
state = a[state].child[mp(sentence[i])]
= a[ss].child[mp(sentence[i])];
for (ss = state; ss != -1; ss = a[ss].match_par)
for (int w : a[ss].match)
matches[i + 1 - words[w].length()].push_back(w);
}
}
开发者ID:TimonKnigge,项目名称:Competitive-Programming,代码行数:13,代码来源:cf-633c.cpp
示例11: flood_fill
void flood_fill(vvi& g)
{
int ct = 0;
memset(&visit,0,sizeof(visit));
for(int i=0;i<g.size();i++)
{
if(!visit[i])
{
dfs(g,i);
ct++;
}
}
cout<<ct<<endl;
}
开发者ID:abusomani,项目名称:UVA,代码行数:14,代码来源:11504(scc).cpp
示例12: 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;
}
开发者ID:fersarr,项目名称:algo,代码行数:46,代码来源:SCC_kosaraju.cpp
示例13: 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;
}
开发者ID:archiver,项目名称:spoj,代码行数:17,代码来源:bytesm2.cpp
示例14: 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);
}
开发者ID:ferrolho,项目名称:feup-contests,代码行数:8,代码来源:henrique-ferrolho.cpp
示例15: 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;
}
开发者ID:MagedMilad,项目名称:Solved_Problems,代码行数:45,代码来源:Problem+F.+Best+of+a+bad+lot.cpp
示例16: 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]);
}
}
开发者ID:manandsea,项目名称:Algorithms,代码行数:9,代码来源:combo+sum.cpp
示例17: 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;
}
开发者ID:pillowpilot,项目名称:clases,代码行数:10,代码来源:code.cpp
示例18: 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;
}
开发者ID:fabchiffre,项目名称:SoccerPlayer_Fuzzy,代码行数:43,代码来源:SoccerPlayer.cpp
示例19: 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;
}
开发者ID:ishanpuranik14,项目名称:Core-Algorithms,代码行数:19,代码来源:parenthesization.cpp
示例20: solve
void solve() {
for (ui i = 0; i < trees.size(); i++) {
float min = -1;
for (ui j = 0; j < trees.size(); j++) {
if (i == j)
continue;
float dist = calcDist(trees[i][0], trees[i][1], trees[i][2],
trees[j][0], trees[j][1], trees[j][2]);
if (dist < min || min == -1)
min = dist;
}
if (min < 10)
answer[(int) min]++;
}
}
开发者ID:ferrolho,项目名称:feup-contests,代码行数:19,代码来源:henrique-ferrolho.cpp
注:本文中的vvi类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论