Division

Let $a$ and $b$ be positive integers. When we do a / b, the decimal part gets truncated, so it is effectively floor division (i.e. $\lfloor \frac{a}{b} \rfloor$). e.g., 5 / 2 == 2.

If we want to do ceiling division (i.e. $\lceil \frac{a}{b} \rceil$), we have to convert one of the arguments into a float/double, then use ceil from <cmath>. e.g., ceil(5 / 2.0) == 3.

<algorithm>

min(a, b) and max(a, b) return the minimum/maximum of $a$ and $b$. Note that $a$ and $b$ need to be of the same type.

Say for an integer $c$, we want to turn it into zero if it is negative, but do nothing if it is zero or positive. Then we would write c = max(c, 0);.

Macros

We can create shorthands for C++ syntax. For example, at the top of the file, we add #define ll long long. Now we can use ll instead of long long throughout the file.


Authored by s16f22