C ++ common pit / stepped pit

C ++ easy to step on pit

Added at any time

  1. While circulating STL not erase ()
//自己写的求交集RE了
for (set <int> ::iterator it = s.begin(); it != s.end(); it++)
    if (*it == x)
        s.erase(it);    //RE

The solution: use vector element to be deleted record, open a new cycle of the vector, the operation can be set.

  1. Redefined operator when using unique () / lower_bound () <should meet strict smaller than (equal to if return false).
  2. priority_queue large root stack, sort in ascending.

Welcome to add

Guess you like

Origin www.cnblogs.com/Decisive/p/11854213.html