アットウィキロゴ

C++ Tips

Vectorのcopy

std::copy(w.begin(), w.end(), back_inserter(v));

priority_queueの要素に構造体等を指定する方法

挿入したいstructを
struct node{
  int cost, num;
  node(int c, int n): cost(c), num(n){}
  bool operator >(const node &e) const{
    return cost > e.cost;
  }
};
とする。ここでソート基準となるoperator>を書いておく。
あとは
priority_queue<node, vector<node>, greater<node> > q;
とすればおk。greaterを指定するとoperator>の逆順(昇順)になる。
priority_queueはdefaultで昇順なのでそれに合わせておいたほうがいいかも。

n次元配列へのstd::fill

例だけ。
int field[n][n];
std::fill((int *)field, (int *)field+n*n, 12345);
とすればよい。
最終更新:2011年06月19日 00:44
ツールボックス

下から選んでください:

新しいページを作成する
ヘルプ / FAQ もご覧ください。