asceD's blog

By asceD, history, 3 months ago, In English,

Like I want it to be n X m size. How to do it?

 
 
 
 

»
3 months ago, # |
Rev. 2   Vote: I like it +2 Vote: I do not like it

a.assign(n,vector<pair<ll,ll> >(m));

  • »
    »
    3 months ago, # ^ |
      Vote: I like it +10 Vote: I do not like it
    vector<vector<ll>> a(3, vector<ll>(5));
    a.resize(3, vector<ll>(3));
    

    Note that in this case vector<vector< ll>> will remain 3x5 size. Be careful with resize.

    • »
      »
      »
      3 months ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Can you please explain why?

      • »
        »
        »
        »
        3 months ago, # ^ |
          Vote: I like it +1 Vote: I do not like it

        void resize(size_type n, const value_type& Val);

        Val used when n is greater than the current container size. For example:

        vector<vector<ll>> a(2, vector<ll>(2, 0));
        a.resize(3, vector<ll>(3, 1));
        

        a contains:

        0 0

        0 0

        1 1 1

»
3 months ago, # |
  Vote: I like it +1 Vote: I do not like it
vector<vector<pair<ll,ll>>> a(n, vector<pair<ll,ll>>(m));

or

vector<vector<pair<ll,ll>>> a;
a.assign(n, vector<pair<ll,ll>>(m));
»
3 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Arigato!