This commit is contained in:
Benjamin Qi 2020-06-08 21:10:26 -04:00
parent 2b77f35528
commit 01cbbfe55b
5 changed files with 92 additions and 5 deletions

View file

@ -7,6 +7,7 @@ order: 1
- Goals
- Module Organization
- Contact Information
<!-- END DESCRIPTION -->
@ -49,6 +50,6 @@ Written with [markdown](https://www.markdownguide.org/cheat-sheet/).
- Add comments regarding difficulty and / or solution sketches.
- Possibly include additional problems.
## Questions
## Contact Information
If you would like to contribute or if you have any questions please reach out to Nathan Wang at <nathan.r.wang@gmail.com> or through social media (some variant of “thecodingwizard”).

View file

@ -2,7 +2,7 @@
slug: /general/practicing
title: How to Practice
author: Benjamin Qi, William Lin, Eric Wei, Nathan Wang, Nathan Chen
order: 5
order: 4
---
How to practice, when to read editorials (analyses), etc.

View file

@ -5,6 +5,13 @@ author: Benjamin Qi
order: 6
---
- Compilation Options
- CppIO Template
- Stress Testing
- Using a Debugger
<!-- END DESCRIPTION -->
## Compilation
I use the following command:
@ -32,7 +39,7 @@ According to [this comment](https://codeforces.com/blog/entry/60999?#comment-449
(someone want to explain these? I don't use)
## Printing
## CppIO Template
Although not feasible if you have to write all code from scratch, I find [this](https://github.com/bqi343/USACO/blob/master/Implementations/content/contest/CppIO.h) very helpful. `dbg()` only produces output when `-DLOCAL` is included as part of the compilation command.
@ -42,6 +49,6 @@ Although not feasible if you have to write all code from scratch, I find [this](
You can use a [simple script](https://github.com/bqi343/USACO/blob/master/Implementations/content/contest/stress.sh) to test two solutions against each other. See Errichto's [video](https://www.youtube.com/watch?v=JXTVOyQpSGM) on testing solutions for more information.
## Debugger
## Using a Debugger
Ok I don't actually know how to use ... (someone else want to add?)

View file

@ -4,3 +4,82 @@ title: C++ Macros
author: Benjamin Qi
order: 7
---
## Introduction
- [GeeksForGeeks](https://www.geeksforgeeks.org/cc-preprocessors/#:~:text=Macros%3A%20Macros%20are%20a%20piece,used%20to%20define%20a%20macro.)
- [GCC Online Docs](https://gcc.gnu.org/onlinedocs/cpp/Macros.html)
- CPH 1.4
## [My Template](https://github.com/bqi343/USACO/blob/master/Implementations/content/contest/template.cpp)
Some comments about specific parts:
### Pairs
```cpp
typedef pair<int,int> pi;
#define mp make_pair
#define f first
#define s second
```
Pretty annoying to keep typing `first` and `second` (especially if you have nested pairs ...)
### Vectors
```cpp
typedef vector<int> vi;
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
```
It's generally a good idea to convert a size to a signed integer before doing anything with it to avoid cases like the following.
```cpp
vi x;
cout << x.size()-1 << "\n"; // 18446744073709551615
cout << sz(x)-1 << "\n"; // -1
```
`all(v)` makes sorting part or all of a vector a bit shorter.
```cpp
vi v = {2,4,1,5,3};
sort(1+all(v)); // {2,1,3,4,5}
sort(all(v)); // {1,2,3,4,5}
```
### Constants
```cpp
const int MOD = 1e9+7; // 998244353;
const int MX = 2e5+5;
const ll INF = 1e18;
const ld PI = acos((ld)-1);
```
$10^9+7$ is a prime that appears quite frequently in programming contests. Interestingly, ```(MOD-1)/2``` is also prime. On the other hand, $998244353-1$ is divisible by $2^{23}$, which is useful for [NTT](https://en.wikipedia.org/wiki/Discrete_Fourier_transform_(general)#Number-theoretic_transform).
Most USACO problems satisfy $N\le 2\cdot 10^5$.
### RNG
```cpp
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());
```
See [neal's blog](https://codeforces.com/blog/entry/61587) about why `rand()` is bad (use `rng()` instead).
### ckmin
```cpp
template<class T> bool ckmin(T& a, const T& b) {
return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) {
return a < b ? a = b, 1 : 0; }
```
See [negCyc](https://github.com/bqi343/USACO/blob/master/Implementations/content/graphs%20(12)/Basics/NegativeCycle%20(7.3).h) for an example of usage.

View file

@ -1,5 +1,5 @@
---
slug: /silver/greedy
slug: /silver/complexity
title: "Time & Space Complexity"
author: Darren Yao
order: 0