关于priority_queue的排列问题
查看原帖
关于priority_queue的排列问题
521554
W1ngD1nGa5ter楼主2025/1/24 08:33

priority_queue默认是大根堆!!! 查询gcc的头文件,其默认模板:

  template<typename _Tp, typename _Sequence = vector<_Tp>,
	   typename _Compare  = less<typename _Sequence::value_type> >

它用lessless的定义如下:

  /// One of the @link comparison_functors comparison functors@endlink.
  template<typename _Tp>
    struct less : public binary_function<_Tp, _Tp, bool>
    {
      _GLIBCXX14_CONSTEXPR
      bool
      operator()(const _Tp& __x, const _Tp& __y) const
      { return __x < __y; }
    };

因此,在用另外一个全局数组h[][]比较时, 函数类cmp的比较operator()(a, b)得写成>

比如:

struct cmp
{
	bool operator()(const pair<int, int> &a, const pair<int, int> &b) { return h[a.first][a.second] > h[b.first][b.second]; }
};

不然就会WA 40pts

2025/1/24 08:33
加载中...