For newcomers to competitive programming, recalling trivial details can consume valuable seconds. To optimize your C++ programming experience, I've compiled a set of tips and tricks for occasional reference:
- Use
S.push()
for characters andS.append()
for strings.- Always pass variables by reference to enhance efficiency.
- When utilizing
log2()
, ensure you place float/double data types inside it.- Keep in mind the power of binary searching for answers.
- Avoid relying solely on memory; think logically about problem-solving.
- Prioritize time complexity; seek the most efficient solution, especially when it significantly impacts the outcome.
- For uncertain approaches, delve deeper into problem-solving or explore alternative methods. Complex solutions for C/D often appear straightforward once discovered.
- Exercise caution with logical expressions, especially when applying them to numbers.
- Consider using a set as an ideal data structure for fast addition, removal, and finding the next greatest element.
- Remember the XOR and sum trick: a+b=a⊕b+2×(a&b).
- Utilize n=n&(n−1) to convert the rightmost 1 to 0, particularly useful for counting the number of 1s.
- n>>1 shifts all bits to the right.
- n<<1 shifts all bits to the left.
These guidelines aim to streamline your coding experience, helping you save time and enhance your problem-solving skills.