当前位置: 首页>>代码示例>>C++>>正文


C++ vi::resize方法代码示例

本文整理汇总了C++中vi::resize方法的典型用法代码示例。如果您正苦于以下问题:C++ vi::resize方法的具体用法?C++ vi::resize怎么用?C++ vi::resize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在vi的用法示例。


在下文中一共展示了vi::resize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main(){
	while(scanf("%d",&N) == 1 && N){
		int sum = 0,ans = INT_MAX,cmax = 0;
		L.resize(N);
		taken.resize(N);
		loop(i,N) {
			scanf("%d",&L[i]);
			sum += L[i];
			cmax = max(cmax,L[i]);
			taken[i] = 0;
		}
		sort(all(L));
		for(int i = sum;i>=1;i--){
			if(sum%i == 0){
				int l = sum/i,n = i;
				if(l >= cmax){
					fill(all(taken),0);
					bool c = possibe(0,0,0,l,n);
					if(c){
						ans = l;
						break;
					} 
				}		
			}
		}
		printf("%d\n",ans);
	}  	
开发者ID:NoureldinYosri,项目名称:competitive-programming,代码行数:27,代码来源:Sticks.cpp

示例2:

 // Constructs the lookup table in O(V log V) time and memory
 lowest_common_ancestor(const vvi& tree = {}, int root = 0) {
     depth.resize(tree.size());
     pos.resize(tree.size());
     vector<visit> tour;
     if (tree.size()) dfs(tree, tour, root, root);
     euler = sparse_table<visit>(tour);
 }
开发者ID:saketh-are,项目名称:contest-library,代码行数:8,代码来源:lowest_common_ancestor.cpp

示例3: main

int main(){
    freopen("1199.txt", "r", stdin);
    //setbuf(stdout, NULL);
    scanf("%d", &N);
    adj = vvi(N, vi(N));
    int total_edge = 0;
    in_degree.resize(N); out_degree.resize(N);
    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            scanf("%d", &adj[i][j]);
            out_degree[i] += adj[i][j];
            in_degree[j] += adj[i][j];
        }
    }
    bool flag = false;
    for(int i = 0; i < N; i++){
        if( (out_degree[i] & 1) || (in_degree[i] & 1)){
            flag = true;
            break;
        }
    }

    if(flag){
        printf("-1\n");
    }
    else{
        vi trace;
        solve(0, trace);
        for(int i = 0; i < trace.size(); i++){
            printf("%d ", trace[i] + 1);
        }
        printf("\n");
    }
    
}
开发者ID:songkwwwwwww,项目名称:study,代码行数:35,代码来源:1199.cpp

示例4: lca

    heavy_light(const vvi &graph, int root) {
        links = lca(graph, 0);

        st = seg_tree<T>(graph.size());
        index.resize(graph.size()), jump.resize(graph.size());
        dfs(root, root, root, graph);
    }
开发者ID:saketh-are,项目名称:contest-library,代码行数:7,代码来源:heavy_light.cpp

示例5: main

int main(){
  int N, M, a, b, c;
  while(cin >> N >> M && N != 0 && M != 0){
    AdjList.resize(N);
    dfs_num.resize(N);
    visited.resize(N);
    dfs_low.resize(N);
    numSCC = dfsNumberCounter = 0;

    for(int i = 0; i < M; i++){
      cin >> a >> b >> c;
      AdjList[a-1].push_back(b-1);
      if(c == 2) AdjList[b-1].push_back(a-1);
    }

    for(int i = 0; i < N; i++)
      if(dfs_num[i] == 0)
	tarjan(i);

    if(numSCC == 1) cout << 1 << endl;
    else cout << 0 << endl;

    visited.clear();
    AdjList.clear();
    dfs_low.clear();
    dfs_num.clear();
    S.clear();
  }
}
开发者ID:mateoatr,项目名称:Competitive-Programming,代码行数:29,代码来源:11838.cpp

示例6: main

int main() {
    int tc;
    cin >> tc;
    while (tc--) {
        int n, m;
        cin >> n >> m;
        AdjList.clear(); AdjList.resize(n);
        for (int i = 0; i < m; i++) {
            int a, b;
            cin >> a >> b;
            AdjList[a].push_back(ii(b, 0));
        }
        bool cac = true;
        int numScc = 0;
        dfs_num.clear(); dfs_num.resize(n, UNVISITED);
        dfs_parent.clear(); dfs_parent.resize(n, 0);
        for(int i = 0; i < n; i++) {
            if(dfs_num[i] == UNVISITED) {
                numScc++;
                if(graphCheck(i)) {
                    cac = false;
                    break;
                }
            }
        }
        if(cac && numScc == 1) cout << "YES\n";
        else cout << "NO\n";
    }
    return 0;
}
开发者ID:mehranagh20,项目名称:uvaSolvedPromblems,代码行数:30,代码来源:10510-Cactus.cpp

示例7: init

void init() {
	pertenece.resize(n);
	rank.resize(n, 0);
	size.resize(n, 1);
	for(int i = 0; i < n; i++) {
		pertenece[i] = i;
	}
}
开发者ID:juancate,项目名称:CompetitivePrograming,代码行数:8,代码来源:highways_kruskal.cpp

示例8: Task

 Task(int _tl, int _testsCnt) {
     tl = _tl;
     testsCnt = _testsCnt;
     averages.resize(testsCnt + 1, 0);
     counters.resize(testsCnt + 1, 0);
     sums.resize(testsCnt + 1, 0);
     averages[testsCnt] = (tl / AVG_CONST) * testsCnt;
 }
开发者ID:kuzmichevdima,项目名称:coding,代码行数:8,代码来源:a_3452.cpp

示例9: scc

void scc () {
	nr.resize (gr.size (), -1);
	low.resize (gr.size ());
	inst.resize (gr.size (), false);
	for (int i = 0; i < gr.size (); ++i) {
		if (nr[i] < 0) {
			visit (i);
		}
	}
}
开发者ID:niklasb,项目名称:tcr,代码行数:10,代码来源:scc_old.cpp

示例10: init

void init(int n) {
	h.resize(n, -1);
	par.resize(n, -1);
	//add 1
	vi v1; v1.pb(1);
	Node z1(1, 1, 0, v1);
	G1.pb(z1);
	h[1] = 1;
	h[0] = 0;
}
开发者ID:mk95kagakushi,项目名称:programming,代码行数:10,代码来源:fast_pow3.cpp

示例11: main

int main () {
    #ifndef ONLINE_JUDGE
    freopen(INP, "r", stdin); freopen(OUT, "w", stdout);
    #endif
    
    scanf("%d", &n);
    order.clear();
    arr1.assign(n+1,0);
    a1.clear();
    FOR(i,1,n) scanf("%d", &a), a1.pb(a);
    REP(i,n) arr1[a1[i]-1] = i+1;
    REP(i,n) order[arr1[i]] = i;
    while(scanf("%d", &a) != EOF){
        arr.assign(n+1,0);
        a2.clear();
        a2.pb(a);
        ans.resize(0);
        len = 0;
        FOR(i,1,n-1) scanf("%d", &a), a2.pb(a);
        REP(i,n) arr[a2[i]-1] = i+1;
        REP(i,n) updateLis(arr[i]);   
        cout << len << endl; 
    }

    return 0;
}
开发者ID:pedrofeijao,项目名称:competitive-programming,代码行数:26,代码来源:UVa+111+History+Grading.cpp

示例12: clear

 void clear()
 {
     dfs_num.clear();
     dfs_num.resize(v+1);
     connectedComp.clear();
     cnt = 0;
 }
开发者ID:techyvish,项目名称:codeforce-problems,代码行数:7,代码来源:uva11504.cpp

示例13: stable_marriage

// calculates the "male optimal" stable marriage (i.e. there
// is no stable marriage where any man prefers his match
// over the one given here) a female optimal matching can be
// found by swapping men and women
// mpref: vector i is the list of i's preferred partners, in
//    *decreasing* order of preference (0 indexed)
// fpref: as above, but for women
// match: a vector (passed in with any size) filled so that
//    position i gives the man matched with woman i
void stable_marriage(const vvi& mpref, const vvi& fpref,
           vi& match) {
  // initially no one matched
  match.resize(mpref.size(), -1); 

  // get a map from (w, m) to w's "rank" for m
  vvi fmap(match.size(), vi(match.size()));
  for(int i = 0; i < match.size(); ++i)
    for(int j = 0; j < match.size(); ++j)
      fmap[i][fpref[i][j]] = j;

  vi next_prop(match.size(), 0);
  queue<int> mfree;
  for(int i = 0; i < match.size(); ++i)
    mfree.push(i);

  while(!mfree.empty()) {
    const int m = mfree.front();
    const int w = mpref[m][next_prop[m]];
    mfree.pop();

    if(match[w] == -1) {
      match[w] = m;
    }
    else if(fmap[w][match[w]] > fmap[w][m]) {
      mfree.push(match[w]);
      match[w] = m;
    }
    else if(++next_prop[m] < match.size()) {
      mfree.push(m);
    }
  }
}
开发者ID:Edgeworth,项目名称:potential-batman,代码行数:42,代码来源:StableMarriage.cpp

示例14: main

int main()
{
	ifstream fin("marathon.in");
	ofstream fout("marathon.out");

	int N; 
	fin >> N;
	points.resize(N);
	for (int i = 0; i < N; ++i)
	{
		fin >> points[i].first >> points[i].second;
	}

	T.resize(N - 2);
	res.resize(N - 2);

	T[0].first = 0;
	T[0].second =  dist_cont(2, N-1);
	res[0] = T[0].first + T[0].second + dist_two(0, 2);
	int result = res[0];

	for (int k = 1; k <= N - 3; ++k)
	{
		T[k].first = T[k - 1].first + dist_two(k - 1, k);
		T[k].second = T[k - 1].second - dist_two(k + 1, k+2);
		res[k] = T[k].first + T[k].second + dist_two(k, k + 2);
		result = min(result, res[k]);
	}
	fout << result << '\n';
	
	return 0;
}
开发者ID:YourRatzon,项目名称:Algorithmic_Problems,代码行数:32,代码来源:marathon.c

示例15: main

int main() {
    ios::sync_with_stdio(0);
    double d;
    int m, tc = 1;
    while( cin >> d >> m) {
        cout << "Case " << tc++ << ":" << endl;
        memo.clear(); memo.resize(105, -1);
        prices.clear(); prices.resize(m + 1);
        prices[0].first = 1; prices[0].second = (d + eps) * 100;
        for(int i = 1; i <= m; i++) {
            int tmp; cin >> tmp >> d;
            prices[i].first = tmp; prices[i].second = (d + eps) * 100;
        }
        string str;
        cin.get();
        getline(cin, str);
        stringstream ss(str);
        int tmp;
        while(ss >> tmp) {
            cout << "Buy " << tmp << " for $" << fixed << setprecision(2) << (double)solve(tmp) / 100 << endl;
        }
    }

    return 0;
}
开发者ID:mehranagh20,项目名称:uvaSolvedPromblems,代码行数:25,代码来源:10980-Lowest-Price-in-Town.cpp


注:本文中的vi::resize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。