+ General

This commit is contained in:
Benjamin Qi 2020-06-08 15:51:58 -04:00
parent 980a592488
commit 31d06ee4f5
26 changed files with 667 additions and 273 deletions

View file

@ -9,8 +9,6 @@ order: 1
<ul class="syllabus-only">
<li>Contest Format</li>
<li>Choosing a Language</li>
<li>Practicing and Debugging</li>
<li>Contest Strategies</li>
</ul>
<!-- END DESCRIPTION -->
@ -19,6 +17,12 @@ Todo:
- Video clip from Brian Dean
- Explains what USACO is all about & how it works
## Introduction
In competitive programming contests, one must solve well-defined problems by writing computer programs under specified constraints ([Wikipedia](https://en.wikipedia.org/wiki/Competitive_programming)). Typically, the most popular language is C++, followed by Java and Python.
[William Lin video!!](https://www.youtube.com/watch?time_continue=1&v=ueNT-w7Oluw)
## Choosing a Language
If you're in Bronze, **Don't worry about the language!** If you already know a language, just use it. You can always switch languages down the road.
@ -34,163 +38,9 @@ Note: A majority of high level contestants use C++ and Java. Between those, C++
Keep in mind that it's easy to switch languages down the road! Don't get caught up on which language to choose. Just pick the one you feel most comfortable with!
## Why C++?
## Language References (provided at IOI)
Although both Python and Java receive two times the C++ time limit in USACO, this is not the case for other websites (ex. CodeForces). Even with the extended time limits, Python and Java sometimes have trouble passing time limits.
- Rewriting the C++ solution for [Wormsort](http://www.usaco.org/index.php?page=viewproblem2&cpid=992) in Python gets TLE on 2/10 cases.
<details>
<summary>Python3 8/10</summary>
```py
# 8/10 test cases ...
fin = open("wormsort.in","r")
lines = [line for line in fin]
N,M = map(int,lines[0].split())
p = list(map(lambda x: int(x)-1,lines[1].split()))
ed = []
for i in range(2,len(lines)):
a,b,w = map(int,lines[i].split())
a -= 1
b -= 1
ed.append([w,a,b])
ed.sort()
ed.reverse()
adj = [[] for i in range(N)]
vis = [0 for i in range(N)]
cnt = 0
def dfs(x):
global cnt
if vis[x] != 0:
return
vis[x] = cnt
for i in adj[x]:
dfs(i)
def ok(mid):
global cnt
for i in range(N):
vis[i] = 0
adj[i].clear()
for i in range(mid):
a,b = ed[i][1],ed[i][2]
adj[a].append(b)
adj[b].append(a)
for i in range(N):
if vis[i] == 0:
cnt += 1
todo = [i]
ind = 0
while ind < len(todo):
x = todo[ind]
ind += 1
vis[x] = cnt
for i in adj[x]:
if vis[i] == 0:
vis[i] = -cnt
todo.append(i)
ok = True
for i in range(N):
if vis[i] != vis[p[i]]:
ok = False
return ok
lo,hi = 0,M
while lo < hi:
mid = (lo+hi)//2
if ok(mid):
hi = mid
else:
lo = mid+1
fout = open("wormsort.out","w")
fout.write(str(-1 if lo == 0 else ed[lo-1][0]))
fout.write('\n')
```
</details>
- A similar solution in Java requires almost 3s, which is fairly close to the time limit of 4s.
<details>
<summary>Java</summary>
```java
import java.io.*; // from Nick Wu
import java.util.*;
public class wormsort {
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new FileReader("wormsort.in"));
StringTokenizer st = new StringTokenizer(br.readLine());
int n = Integer.parseInt(st.nextToken());
int m = Integer.parseInt(st.nextToken());
loc = new int[n];
component = new int[n];
edges = new LinkedList[n];
for(int i = 0; i < n; i++) edges[i] = new LinkedList<>();
lhs = new int[m];
rhs = new int[m];
weight = new int[m];
st = new StringTokenizer(br.readLine());
for(int i = 0; i < n; i++) loc[i] = Integer.parseInt(st.nextToken())-1;
for(int i = 0; i < m; i++) {
st = new StringTokenizer(br.readLine());
lhs[i] = Integer.parseInt(st.nextToken())-1;
rhs[i] = Integer.parseInt(st.nextToken())-1;
weight[i] = Integer.parseInt(st.nextToken());
}
br.close();
int minW = 0;
int maxW = 1000000001;
while(minW != maxW) {
int mid = (minW + maxW + 1) / 2;
if(valid(mid)) minW = mid;
else maxW = mid-1;
}
if(minW > 1e9) minW = -1;
PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter("wormsort.out")));
pw.println(minW);
pw.close();
}
static int[] loc, lhs, rhs, weight;
static LinkedList<Integer>[] edges;
static int[] component;
private static void dfs(int curr, int label) {
if(component[curr] == label) return;
component[curr] = label;
for(int child: edges[curr]) dfs(child, label);
}
private static boolean valid(int minW) {
Arrays.fill(component, -1);
for(int i = 0; i < edges.length; i++) edges[i].clear();
for(int i = 0; i < lhs.length; i++) {
if(weight[i] >= minW) {
edges[lhs[i]].add(rhs[i]);
edges[rhs[i]].add(lhs[i]);
}
}
int numcomps = 0;
for(int i = 0; i < component.length; i++) {
if(component[i] < 0) {
dfs(i, numcomps++);
}
}
for(int i = 0; i < loc.length; i++) {
if(component[i] != component[loc[i]]) return false;
}
return true;
}
}
```
</details>
Also, Java lacks features such as `#define`, `typedef`, and `auto` that are present in C++ (which some contestants use extensively).
- [C++](https://en.cppreference.com/w/)
- [Additional C++ reference (not provided at IOI)](http://www.cplusplus.com/)
- [Java](https://docs.oracle.com/javase/8/docs/api/overview-summary.html)
- [Python3](https://docs.python.org/3/reference/)

View file

@ -0,0 +1,173 @@
---
slug: /intro/why-cpp
title: Why C++?
author: Benjamin Qi
order: 1
---
A few reasons why choice of language matters significantly outside of bronze.
## Time Limit
Although both Python and Java receive two times the C++ time limit in USACO, this is not the case for most other websites (ex. CodeForces). Even with the extended time limits, Python and Java sometimes have trouble passing.
- Rewriting the C++ solution for [USACO Silver Wormsort](http://www.usaco.org/index.php?page=viewproblem2&cpid=992) in Python receives TLE (Time Limit Exceeded) on 2/10 cases.
<details>
<summary>Python3 8/10 Solution</summary>
```py
# 8/10 test cases ...
fin = open("wormsort.in","r")
lines = [line for line in fin]
N,M = map(int,lines[0].split())
p = list(map(lambda x: int(x)-1,lines[1].split()))
ed = []
for i in range(2,len(lines)):
a,b,w = map(int,lines[i].split())
a -= 1
b -= 1
ed.append([w,a,b])
ed.sort()
ed.reverse()
adj = [[] for i in range(N)]
vis = [0 for i in range(N)]
cnt = 0
def dfs(x):
global cnt
if vis[x] != 0:
return
vis[x] = cnt
for i in adj[x]:
dfs(i)
def ok(mid):
global cnt
for i in range(N):
vis[i] = 0
adj[i].clear()
for i in range(mid):
a,b = ed[i][1],ed[i][2]
adj[a].append(b)
adj[b].append(a)
for i in range(N):
if vis[i] == 0:
cnt += 1
todo = [i]
ind = 0
while ind < len(todo):
x = todo[ind]
ind += 1
vis[x] = cnt
for i in adj[x]:
if vis[i] == 0:
vis[i] = -cnt
todo.append(i)
ok = True
for i in range(N):
if vis[i] != vis[p[i]]:
ok = False
return ok
lo,hi = 0,M
while lo < hi:
mid = (lo+hi)//2
if ok(mid):
hi = mid
else:
lo = mid+1
fout = open("wormsort.out","w")
fout.write(str(-1 if lo == 0 else ed[lo-1][0]))
fout.write('\n')
```
</details>
- A similar solution in Java requires almost 3s, which is fairly close to the time limit of 4s.
<details>
<summary>Java Solution</summary>
```java
import java.io.*; // from Nick Wu
import java.util.*;
public class wormsort {
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new FileReader("wormsort.in"));
StringTokenizer st = new StringTokenizer(br.readLine());
int n = Integer.parseInt(st.nextToken());
int m = Integer.parseInt(st.nextToken());
loc = new int[n];
component = new int[n];
edges = new LinkedList[n];
for(int i = 0; i < n; i++) edges[i] = new LinkedList<>();
lhs = new int[m];
rhs = new int[m];
weight = new int[m];
st = new StringTokenizer(br.readLine());
for(int i = 0; i < n; i++) loc[i] = Integer.parseInt(st.nextToken())-1;
for(int i = 0; i < m; i++) {
st = new StringTokenizer(br.readLine());
lhs[i] = Integer.parseInt(st.nextToken())-1;
rhs[i] = Integer.parseInt(st.nextToken())-1;
weight[i] = Integer.parseInt(st.nextToken());
}
br.close();
int minW = 0;
int maxW = 1000000001;
while(minW != maxW) {
int mid = (minW + maxW + 1) / 2;
if(valid(mid)) minW = mid;
else maxW = mid-1;
}
if(minW > 1e9) minW = -1;
PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter("wormsort.out")));
pw.println(minW);
pw.close();
}
static int[] loc, lhs, rhs, weight;
static LinkedList<Integer>[] edges;
static int[] component;
private static void dfs(int curr, int label) {
if(component[curr] == label) return;
component[curr] = label;
for(int child: edges[curr]) dfs(child, label);
}
private static boolean valid(int minW) {
Arrays.fill(component, -1);
for(int i = 0; i < edges.length; i++) edges[i].clear();
for(int i = 0; i < lhs.length; i++) {
if(weight[i] >= minW) {
edges[lhs[i]].add(rhs[i]);
edges[rhs[i]].add(lhs[i]);
}
}
int numcomps = 0;
for(int i = 0; i < component.length; i++) {
if(component[i] < 0) {
dfs(i, numcomps++);
}
}
for(int i = 0; i < loc.length; i++) {
if(component[i] != component[loc[i]]) return false;
}
return true;
}
}
```
</details>
## Other
- Python lacks a data structure that keeps its keys in sorted order (the equivalent of `set` in C++), which is required for some silver problems.
- Java lacks features such as `#define`, `typedef`, and `auto` that are present in C++ (which some contestants rely on extensively).
- Problemsetters don't always test Java solutions (and rarely Python) when setting the constraints.

View file

@ -11,6 +11,8 @@ Here's what you should learn before reading these resources.
These resources do not teach you how to code. We recommend you learn roughly the first half of AP Computer Science A before continuing. If you do not meet these prerequisites, you can go to the resources below to get started.
Familiarity with contest math (ex. AIME qualification) is helpful but not required.
Expected Knowledge:
- Variables
@ -25,34 +27,22 @@ Expected Knowledge:
- Arrays
- Multidimensional Arrays
## Resources for Learning to Code
## Introductory Resources
### Learning to Code
[Sololearn](https://www.sololearn.com/) has courses on C++, Java, and Python. You don't have to complete the full course.
- For C++, we recommend you finish Sololearn up to (but not including) "More on Classes."
## Using C++
- For C++, we recommend you finish Sololearn up to (but not including) "More on Classes."
[[info | Pro Tip]]
| You do not need to learn pointers (for now). Knowledge of structs and classes is useful but not required.
<div class="h-2"></div>
### Getting Started
Here's a basic C++ template you may find useful:
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
// these two lines open the file into the standard input/output,
// so you can just use cin/cout.
freopen("file.in", "r", stdin);
freopen("file.out", "w", stdout);
// Code goes here!!
return 0;
}
```
- [CodeSignal](https://codesignal.com/)
- good place to practice basics
- [IOI: Getting Started](https://ioinformatics.org/page/getting-started/14)
- [Philippines OI: Prepare](https://noi.ph/prepare/)
- [Schedule for Beginners](https://www.quora.com/What-is-a-good-schedule-to-follow-for-becoming-better-at-competitive-programming-for-beginners)
- [E869120 Tutorial](http://codeforces.com/blog/entry/53341)

View file

@ -0,0 +1,36 @@
---
slug: /intro/running-cpp
title: Running C++
author: Nathan Wang, Benjamin Qi
order: 2
---
How to run C++ locally.
<!-- END DESCRIPTION -->
## Running C++ Locally
(todo)
## Using C++
<div class="h-2"></div>
Here's a basic C++ template you may find useful:
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
// these two lines open the file into the standard input/output,
// so you can just use cin/cout.
freopen("file.in", "r", stdin); // read from file.in
freopen("file.out", "w", stdout); // write to file.out
// Code goes here!!
}
```

View file

@ -0,0 +1,128 @@
# C++
## Command Line (Mac)
### Option 1
```
brew install gcc
```
According to [this](https://stackoverflow.com/questions/30998890/installing-opencv-with-brew-never-finishes) if brew doesn't seem to finish for a long time then
```
brew install gcc --force-bottle
```
probably suffices.
### Option 2 (Old))
Follow the instructions [here](https://wiki.helsinki.fi/display/HUGG/GNU+compiler+install+on+Mac+OS+X?fbclid=IwAR3bnM6A_kTgXD2p5nOfVbxRRQ4nHMj89jllNy1-zdtfXfcq1czbSoXiWgE). Step 4 will give errors but it should still install.
### Confirmation
You should be able to compile with g++ or maybe g++-#, where # is the version number (currently 9). Running the following command:
```
g++-9 --version
```
should display something like this:
```
g++-9 (Homebrew GCC 9.2.0_2) 9.2.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
```
## Shortcuts
Open your bash profile with a text editor such as gedit (or sublime text).
```
brew install gedit
gedit ~/.zshenv
```
You can add aliases and functions here, such as the following:
```
alias clr="clear"
alias ZES='source ~/.zshenv'
alias ZEO='subl ~/.zshenv'
alias IMPL='cd ~/Documents/GitHub/USACO/Implementations/'
co() {
g++-9 -std=c++11 -O2 -Wl,-stack_size -Wl,0x10000000 -Wall -Wextra -o $1 $1.cpp
}
run() {
co $1 && ./$1
}
```
Now you can easily run C++ from the command line by calling run.
```
run [prog name]
```
## Troubleshooting
Make sure you have installed XCode command line tools.
```
xcode-select --install # make sure x-code command line tools are installed
softwareupdate --list
softwareupdate -i -a # installs everything
```
### OS X Mojave
Navigate to your bash profile
```
gedit ~/.bash_profile
```
and add the following line:
```
export CPLUS_INCLUDE_PATH="/usr/local/include/c++/8.1.0/:/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include:$CPLUS_INCLUDE_PATH"
```
### OS X Catalina
Maybe the following links are helpful?
* [StackOverflow](https://stackoverflow.com/questions/58278260/cant-compile-a-c-program-on-a-mac-after-upgrading-to-catalina-10-15)
* [SolarianProgrammer](https://solarianprogrammer.com/2019/10/12/compiling-gcc-macos/)
~~Whoops I couldn't figure out how to use g++ successfully D:~~ Turns out that g++ was linked to g++-8 instead of g++-9, changing it now works.
## Tools
### Online
* [CSAcademy](https://csacademy.com/workspace/)
* I used this a lot until the queue time limits got rlly annoying
* [Ideone](http://ideone.com/)
* seems okay if you use an ad blocker
* sometimes randomly erases your code when you first create it (so get in the habit of copying your code before creating it :P)
### Local IDEs
* [Geany](https://www.geany.org/)
* [Visual Studio Code](https://code.visualstudio.com/)
* [XCode](https://developer.apple.com/xcode/)
* mac
* [Codeblocks](http://www.codeblocks.org/)
* bad on mac :(
### Text Editors
* [Sublime Text 3](https://www.sublimetext.com/)
* [Editing Build Settings](https://stackoverflow.com/questions/23789410/how-to-edit-sublime-text-build-settings)
* [FastOlympicCoding Addon](https://github.com/Jatana/FastOlympicCoding)
* [Symlink](https://www.sublimetext.com/docs/3/osx_command_line.html)
* Using '/usr/local/bin/subl' instead of '~/bin/subl' worked for me on OS X Mojave.
* [Atom](https://atom.io/)
## Useful Links
### Reference
* [cplusplus](http://www.cplusplus.com/reference/)
* [cppreference](http://en.cppreference.com/w/)
### Other
* [Intro to Command Line](http://blog.teamtreehouse.com/introduction-to-the-mac-os-x-command-line)
* [Command Line Shortcuts](https://jonsuh.com/blog/bash-command-line-shortcuts/)
* [Run Python Script](https://stackoverflow.com/questions/7855996/cant-run-python-py-files-from-terminal-on-mac)
* [Competitive C++ Style Guide](https://codeforces.com/blog/entry/64218)

View file

@ -0,0 +1,105 @@
---
slug: /intro/contests
title: Contests
author: Benjamin Qi
order: 5
---
See [clist.by](https://clist.by/coder/bqi343/) for an extensive list. Most of the contests which I do are a subset of those shown in "Programming Contests.png". A link to my google calendar for contests is available [here.](https://calendar.google.com/calendar?cid=Y2s5ZjdmZDBkNjdmOGFxZ2oxbDVrMHJ1OGtAZ3JvdXAuY2FsZW5kYXIuZ29vZ2xlLmNvbQ) See the other page for olympiads such as USACO.
Make sure to [upsolve](https://en.wiktionary.org/wiki/upsolve) after the contest ends! I particularly enjoy problems from AtCoder and CSAcademy. :)
* [AtCoder](https://beta.atcoder.jp/contests/archive)
* Contests
* Beginner / Regular: 4 problems, 100 min
* Grand: 6 problems, ~110 min
* [Visualizer](https://kenkoooo.com/atcoder/#/table/Benq)
* I've done nearly all of the AGC problems.
* [Codeforces](http://codeforces.com/problemset)
* Contests
* Div 2, Div 1: 5 problems, 2 hrs
* Archive
* problem quality, difficulty ratings are ok but not always great
* [Topcoder](https://www.topcoder.com/my-dashboard/)
* Div 2, Div 1
* 75 min coding, 15 min challenge
* [Don Mills OJ](http://dmoj.ca/)
* [HackerEarth](http://hackerearth.com/)
* Monthly "Easy"
* [Kattis](https://open.kattis.com/)
* random ICPC stuff
* [Codechef](http://codechef.com/)
* Lunchtime, Cookoff
* [Google Kickstart](https://codingcompetitions.withgoogle.com/kickstart): Feb - Nov
The following websites do not hold regular contests anymore, but they're still worth looking at.
* [CS Academy](https://csacademy.com/contest/archive/)
* Contests
* Div 2: 5 problems, 2 hrs
* Open: 7 problems, 2 hrs
* no more? D:
* Archive
* short statements, editorials
* solve statistics
* ability to view best solutions
* I've done nearly all of the problems.
* [HackerRank](https://www.hackerrank.com/dashboard)
* HourRank: 3-4 problems, 1 hr
* 101 Hack: 5 problems, 2 hrs
## Annual Contests
* [Google Code Jam](https://code.google.com/codejam/): Apr
* 25 from R3
* [Facebook Hacker Cup](https://www.facebook.com/hackercup/): Jun-Jul -> Oct
* 25 from R3
* [Topcoder Open](https://tco19.topcoder.com/): Apr-Aug -> Nov
* 4 from SRMs
* 10 from R4
* 2 from Wildcard
* [AtCoder World Tour Finals](https://codeforces.com/blog/entry/56623)
* 8 from AGC
* [Bubble Cup](http://bubblecup.org/): Apr
* [BattleCode](https://www.battlecode.org): Jan
No Longer Active?
* [IPSC](https://ipsc.ksp.sk/rules): July
* [Russian Code Cup](http://www.russiancodecup.ru/en/): March
* [Yandex Algorithm](https://contest.yandex.ru/contest-list/): April
* [SnackDown](https://www.codechef.com/snackdown): Sep-Dec -> Feb
* Global: 15 with travel expenses paid, 10 additional
## US High School
* [VT HSPC](https://icpc.cs.vt.edu/#/hscontest2017)
* Online
* 5 hours
* [Kattis](https://open.kattis.com/problem-sources/2016%20Virginia%20Tech%20High%20School%20Programming%20Contest)
* December
* [UCF HSPT](https://hspt.ucfprogrammingteam.org/index.php/hspt-online-edition)
* Online
* 4 hours
* December
* [Cornell HSPC](https://www.cs.cornell.edu/events/cornell-high-school-programming-contest)
* [2019](https://cornell-hspc19.kattis.com/problems)
## Codeforces Tools
* [Stopstalk](https://www.stopstalk.com)
* [Code Drills](http://code-drills.com/)
* [CF Visualizer](http://cfviz.netlify.com/compare.html)
* [CF Rating Predictor](https://chrome.google.com/webstore/detail/cf-predictor/ocfloejijfhhkkdmheodbaanephbnfhn)
* [CF Command Line](https://codeforces.com/blog/entry/66552)
* [CF Editor](https://codeforces.com/blog/entry/72952)
* [CF Enhancer](https://chrome.google.com/webstore/detail/codeforces-enhancer/ocmandagmgmkcplckgnfgaokpgkfenmp)
* no longer works
## Contest Tools
* [2D Geo Visualizer](https://codeforces.com/blog/entry/70330)
* [CSA Graph Editor (+ Geo Visualizer + Diff Tool)](https://csacademy.com/app/graph_editor/)
* [Desmos Grapher](https://www.desmos.com/calculator)
* [Wolfram Alpha](https://www.wolframalpha.com/)
* [OEIS](https://oeis.org/)

View file

@ -0,0 +1,7 @@
(compilation flags)
(printing)
* stress.sh:
* Source: [Errichto - testing sols](https://www.youtube.com/watch?v=JXTVOyQpSGM)

View file

@ -0,0 +1,59 @@
# Olympiads
> Hello, Which online judge should I practice more to do well in **IOI** ?
> the closest OJ for IOI style?
> Do you have any magic problems sets to suggest?
## National
See [here](https://ioinformatics.org/page/members/7) for additional links. The [OI Checklist](https://oichecklist.pythonanywhere.com/) is a great way to track your progress. :)
* [USA](http://www.usaco.org/)
* Format
* Bronze, Silver, Gold, Platinum Divisions
* 3 problems, 4 hrs
* [Very Old Gold Probs](http://tjsct.wikidot.com/usaco/)
* [USACO Training](http://train.usaco.org/usacogate)
* not particularly beginner-friendly but still helpful
* somewhat outdated in the sense that it lacks topics which are now quite common (ex. segment tree)
* if you're unsure about whether it will be useful, you might as well try it and see where you get stuck :P
* personally, I did the first five chapters in one summer (though I had to look up some hints ...)
* [article :o](https://www.usenix.org/legacy/bodinfo/bod/bodmarch10/future.pdf)
* [Japan](https://www.ioi-jp.org/)
* [Open Contests](https://contests.ioi-jp.org/)
* see [oj.uz](https://oj.uz/problems/source/45)
* [Poland](https://szkopul.edu.pl/portal/)
* [Solutions (in Polish)](https://www.oi.edu.pl/l/40/)
* [Canada](https://cemc.math.uwaterloo.ca/contests/computing.html)
* [WCIPEG](https://wcipeg.com/problems/cat%3Dccc%2Cshow%3D50)
* [DMOJ](https://dmoj.ca/problems/?category=24)
* [Croatia](http://hsin.hr/coci/)
* not full feedback
* [Indonesia](https://competition.ia-toki.org/contests)
* monthly
* [Philippines](https://noi.ph/past-problems/)
* Other
* [China (WCIPEG)](https://wcipeg.com/problems/cat%3Dnoi%2Cshow%3D50)
* [Lithuania](http://online.lmio.lt/)
* [Australia](https://orac.amt.edu.au/)
* [Italy](https://training.olinfo.it/#/overview)
## International
* IOI
* Online Judges
* [Yandex](https://contest.yandex.com/ioi/)
* [WCIPEG](https://wcipeg.com/problems/cat%3Dioi%2Cshow%3D50)
* [DMOJ](https://dmoj.ca/problems/?category=5)
* [oj.uz](https://oj.uz/problems/source/22)
* Misc
* [List of 2017 IOI Participants](http://weaselcrow.com/pro/cf/ioi2017/)
* [IOI 2018 Syllabus](https://people.ksp.sk/~misof/ioi-syllabus/ioi-syllabus.pdf)
* [Baltic OI](http://www.boi2017.org/)
* [CEOI](http://ceoi.inf.elte.hu/)
* submit BOI / CEOI at [CSES](https://cses.fi/)
* [Balkan OI](http://boi2018.ro/home)
* [IZhO](https://oj.uz/problems/source/24)
* [APIO](http://apio-olympiad.org/)
* [IOIT](http://ioit.altervista.org/2018-teams-and-contests-.html)
* [InfO(1) cup](http://info1cup.com/)

View file

View file

@ -5,18 +5,16 @@ author: Benjamin Qi
order: 5
---
Helpful Links! Some (especially CPH) will be mentioned again in later modules.
Helpful Links! Some (such as CPH and Intro to USACO) will be mentioned again in later modules.
<!-- END DESCRIPTION -->
Use [clist.by](https://clist.by/coder/bqi343/) to track your progress!
### Lists
## Lists
* [USACO Resources Page](http://www.usaco.org/index.php?page=resources)
* [Awesome List (Inishan)](http://codeforces.com/blog/entry/23054)
### Books
## Books
* [Competitive Programmer's Handbook (CPH)](https://cses.fi/book/book.pdf)
* The [CSES problemset](https://cses.fi/problemset/) (now at 200 problems) is quite good!
@ -31,17 +29,19 @@ Use [clist.by](https://clist.by/coder/bqi343/) to track your progress!
* [Competitive Programming 4](https://cpbook.net/) is the latest edition of the book (with significant additions) but costs money.
* Release date is July 19th, 2020.
* [Samuel Hsiang - CS Guide](https://github.com/alwayswimmin/cs_guide)
* [TJSCT](https://activities.tjhsst.edu/sct/)
* [TJIOI](https://github.com/tjsct/tjioi-study-guide)
* [Principles of Algorithmic Problem Solving](http://www.csc.kth.se/~jsannemo/slask/main.pdf)
* [Cracking the Coding Interview](http://www.crackingthecodinginterview.com/) is a good book specifically for programming interviews (it is not needed for USACO).
### Courses
## Courses
* [Competitive Programming Course (SuprDewd)](https://github.com/SuprDewd/T-414-AFLV)
* [Cousera Algorithms Pt 1 (and Pt 2)](https://www.coursera.org/learn/algorithms-part1)
* [Carnegie-Mellon ICPC](https://contest.cs.cmu.edu/295/f17/)
* [VPlanet](https://vplanetcoding.com/)
### Algorithm Collections
## Algorithm Collections
* [CSAcademy](https://csacademy.com/lessons/)
* [cp-algorithms](https://cp-algorithms.com/)
@ -49,3 +49,4 @@ Use [clist.by](https://clist.by/coder/bqi343/) to track your progress!
* [bqi343 Github](https://github.com/bqi343/USACO)
* [Topcoder Tutorials](http://www.topcoder.com/community/data-science/data-science-tutorials/)
* [List of CF Tutorials](http://codeforces.com/blog/entry/57282)
* [ekzlib](http://ekzlib.herokuapp.com)

View file

View file

@ -12,10 +12,22 @@ order: 1
# Tutorials
- Intro to USACO, Chapter 9
- Interval Cover
- CPH 6
- [CPC.5](https://github.com/SuprDewd/T-414-AFLV/tree/master/05_greedy_algorithms)
# Problems
USACO
- [USACO Why Did the Cow Cross the Road](http://www.usaco.org/index.php?page=viewproblem2&cpid=714)
- [USACO Rest Stops](http://www.usaco.org/index.php?page=viewproblem2&cpid=810)
- [USACO High Card Wins](http://usaco.org/index.php?page=viewproblem2&cpid=571)
- [USACO High Card Wins](http://usaco.org/index.php?page=viewproblem2&cpid=571)
Misc
- [Sure Bet](https://csacademy.com/contest/archive/task/sure-bet/)
- [Did you Mean...](http://codeforces.com/contest/860/problem/A)
- [Permutation](http://codeforces.com/problemset/problem/864/D)
- [Bus](http://codeforces.com/problemset/problem/864/C)
- [Kayaking](http://codeforces.com/problemset/problem/863/B)

View file

@ -8,7 +8,7 @@ prerequisites:
- Silver - Sorting
---
Binary search can be used on monotonic functions for a logarithmic runtime.
[Binary search](https://en.wikipedia.org/wiki/Binary_search_algorithm) can be used on monotonic functions for a logarithmic runtime.
<!-- END DESCRIPTION -->
@ -18,8 +18,11 @@ Binary search can be used on monotonic functions for a logarithmic runtime.
## Tutorial
- [GeeksForGeeks](https://www.geeksforgeeks.org/binary-search/)
- [Wikipedia](https://en.wikipedia.org/wiki/Binary_search_algorithm)
- CSES 3.3
- [Topcoder Binary Search](https://www.topcoder.com/community/data-science/data-science-tutorials/binary-search/)
- [CSAcademy Binary Search](https://csacademy.com/lesson/binary_search)
- [KA Binary Search](https://www.khanacademy.org/computing/computer-science/algorithms/binary-search/a/binary-search)
- [GeeksForGeeks](https://www.geeksforgeeks.org/binary-search/)
### Library Functions to do Binary Search
@ -41,13 +44,24 @@ Binary search can be used on monotonic functions for a logarithmic runtime.
Oftentimes used when you need to find the minimum or maximum of some quantity such that it satisfies some property.
### Tutorial
- Intro to USACO 12.1
### Problems
USACO
- [USACO Silver Cownvention](http://www.usaco.org/index.php?page=viewproblem2&cpid=858)
- [USACO Silver Cow Dance](http://www.usaco.org/index.php?page=viewproblem2&cpid=690)
- [USACO Silver Social Distancing](http://www.usaco.org/index.php?page=viewproblem2&cpid=1038)
- [USACO Silver Angry Cows](http://usaco.org/index.php?page=viewproblem2&cpid=594)
- [USACO Silver Loan Repayment](http://www.usaco.org/index.php?page=viewproblem2&cpid=991)
- Also needs some math and rather tricky "sqrt" analysis
- Also needs some math and rather tricky "sqrt" analysis
Misc
- [The Meeting Place Cannot Be Changed](http://codeforces.com/contest/782/problem/B) [](48)
- [Preparing for Merge Sort](http://codeforces.com/contest/847/problem/B) [](53)
- [Level Generation](http://codeforces.com/problemset/problem/818/F) [](54)
- [Packmen](http://codeforces.com/contest/847/problem/E) [](57)
- [Office Keys](http://codeforces.com/problemset/problem/830/A) [](60)

View file

@ -19,8 +19,16 @@ prerequisites:
## Problems
- [CSES Sum of Two Values](https://cses.fi/problemset/task/1640)
- [CSES Maximum Subarray Sum](https://cses.fi/problemset/task/1643)
- CSES
- [Sum of Two Values](https://cses.fi/problemset/task/1640)
- [Maximum Subarray Sum](https://cses.fi/problemset/task/1643)
- CF
- [Cellular Network](http://codeforces.com/problemset/problem/702/C) [](48)
- [USB vs. PS/2](http://codeforces.com/problemset/problem/762/B) [](53)
- [K-Good Segment](http://codeforces.com/problemset/problem/616/D) [](53)
- [(Long Title))](http://codeforces.com/problemset/problem/814/C) [](54)
- [Jury Meeting](http://codeforces.com/problemset/problem/853/B) [](90)
- USACO??
## Extensions

View file

@ -12,8 +12,6 @@ Compute shortest paths where all edge weights are 1.
<!-- END DESCRIPTION -->
## Breadth First Search
- [CSES Message Route](https://cses.fi/problemset/task/1667)
### Tutorial
@ -29,5 +27,6 @@ Compute shortest paths where all edge weights are 1.
- [CSAcademy BFS-DFS](https://csacademy.com/contest/round-41/task/bfs-dfs/) [](50)
- [Cow Navigation](http://www.usaco.org/index.php?page=viewproblem2&cpid=695)
- [Dream](http://www.usaco.org/index.php?page=viewproblem2&cpid=575)
- bad problem ...
- [Lasers](http://www.usaco.org/index.php?page=viewproblem2&cpid=671)
- [Monsters](https://cses.fi/problemset/task/1194)

View file

@ -18,11 +18,12 @@ A [topological sort](https://en.wikipedia.org/wiki/Topological_sorting) of a dir
## Tutorial
(BFS Implementation?)
- CPH 16.1, 16.2
- DFS
- [cp-algorithms](https://cp-algorithms.com/graph/topological-sort.html)
- DFS
- [CSAcademy](https://csacademy.com/lesson/topological_sorting)
- both BFS, DFS
## Problems

View file

@ -68,18 +68,20 @@ Use the *Floyd-Warshall* algorithm.
## Negative Edge Weights
Hasn't appeared in recent USACO Gold as far as I know. Usually Bellman-Ford is used. If no negative cycles, can use [Shortest Path Faster Algorithm](https://en.wikipedia.org/wiki/Shortest_Path_Faster_Algorithm) or modify Dijkstra slightly (though the same running time bound no longer applies).
- Hasn't appeared in recent USACO Gold as far as I know.
- Usually Bellman-Ford is used.
- If no negative cycles, can use [Shortest Path Faster Algorithm](https://en.wikipedia.org/wiki/Shortest_Path_Faster_Algorithm) or modify Dijkstra slightly (though the same running time bound no longer applies).
### Tutorial
* [cp-algo Bellman Ford](https://cp-algorithms.com/graph/bellman_ford.html)
* [Topcoder Graphs Pt 3](https://www.topcoder.com/community/data-science/data-science-tutorials/introduction-to-graphs-and-their-data-structures-section-3/)
- [cp-algo Bellman Ford](https://cp-algorithms.com/graph/bellman_ford.html)
- [Topcoder Graphs Pt 3](https://www.topcoder.com/community/data-science/data-science-tutorials/introduction-to-graphs-and-their-data-structures-section-3/)
You can also use shortest path algorithms to solve the following problem (a very simple [linear program](https://en.wikipedia.org/wiki/Linear_programming)).
> Given variables $x_1,x_2,\ldots,x_N$ with constraints in the form $x_i-x_j\ge c$, compute a feasible solution.
* [Linear Programming Trick](https://www.cs.rit.edu/~spr/COURSES/ALG/MIT/lec18.pdf)
- [Linear Programming Trick](https://www.cs.rit.edu/~spr/COURSES/ALG/MIT/lec18.pdf)
### Problems

View file

@ -51,8 +51,4 @@ Disjoint Set Union and Minimum Spanning Trees
## Other Problems
- [Birthday Gifts](https://www.hackerearth.com/practice/math/combinatorics/inclusion-exclusion/practice-problems/algorithm/mancunian-and-birthday-gifts-d44faa15/) [](73)
- [Spanning Tree Fraction](https://www.hackerrank.com/contests/w31/challenges/spanning-tree-fraction) [](78)
## Boruvka?
(add)
- [Spanning Tree Fraction](https://www.hackerrank.com/contests/w31/challenges/spanning-tree-fraction) [](78)

View file

@ -89,4 +89,4 @@ Note that if it were not the case that all elements of the input array were dist
* aka [Sorting Steps](https://csacademy.com/contest/round-42/task/sorting-steps/) [](42)
* Of course, this doesn't require anything other than sorting but fast range sum queries may make this easier.
* [Twin Permutations](https://www.hackerearth.com/practice/data-structures/advanced-data-structures/fenwick-binary-indexed-trees/practice-problems/algorithm/mancunian-and-twin-permutations-d988930c/description/)
* Offline 2D -> 1D
* Offline 2D queries can be done with a 1D data structure

View file

@ -22,9 +22,26 @@ Also see here: https://codeforces.com/blog/entry/77137
<!-- END DESCRIPTION -->
* Tutorial
* CPH (23, Matrices)
* Problems
* [Currencies](https://www.hackerrank.com/contests/gs-codesprint/challenges/currencies) [](107)
- Tutorial
- CPH (23, Matrices)
- Problems
- [Currencies](https://www.hackerrank.com/contests/gs-codesprint/challenges/currencies) [](107)
COWBASIC
(old)
### 4
* Eratosthenes' Sieve
* Tutorial
* CPH (21, NT)
### 5
* Modular Arithmetic
* Modular Inverse
* Chinese Remainder Theorem
* Euler's Theorem, Phi Function
* Discrete Logarithm

View file

@ -15,21 +15,50 @@ You should know basic operations like cross product and dot product. For platinu
### Tutorial
- CPH 29, 30.1
- [TopCoder](https://www.topcoder.com/community/competitive-programming/tutorials/geometry-concepts-basic-concepts/)
- [CPC.12](https://github.com/SuprDewd/T-414-AFLV/tree/master/12_geometry)
- basic geometry
- convex hulls
- polygon area
- point in polygon
- closest pair of points
- CPH 29
- [TopCoder - Basic Geometry Concepts](https://www.topcoder.com/community/competitive-programming/tutorials/geometry-concepts-basic-concepts/)
- [CF - Point Class](https://codeforces.com/blog/entry/48122)
- [C++ - std::complex](https://codeforces.com/blog/entry/22175)
- [cp-algo - "Elementary Operations"](https://cp-algorithms.com/)
- [vlecomte - geo book](https://codeforces.com/blog/entry/59129)
- [cp-algo - Geometry: "Elementary Operations"](https://cp-algorithms.com/)
- [vlecomte - Geometry Handbook](https://codeforces.com/blog/entry/59129)
- [My Templates](https://github.com/bqi343/USACO/tree/master/Implementations/content/geometry%20(13)/Primitives)
### Problems
- Template Testing
- [Kattis Segment Distance](https://open.kattis.com/problems/segmentdistance)
- [Kattis Segment Intersection](https://open.kattis.com/problems/segmentintersection)
- [Kattis Point in Polygon](https://open.kattis.com/problems/pointinpolygon)
- [Kattis Polygon Area](https://open.kattis.com/problems/polygonarea)
- [Kattis Max Collinear](https://open.kattis.com/problems/maxcolinear)
- Misc
- [Arpa & Geo](http://codeforces.com/problemset/problem/851/B)
- [Tell Your World](http://codeforces.com/problemset/problem/849/B)
- [Gleb & Pizza](http://codeforces.com/problemset/problem/842/B)
- [Birthday Cake](https://open.kattis.com/problems/birthdaycake)
- [Racing Off Track](https://open.kattis.com/contests/acpc17open/problems/racingofftrack)
- [TopCoder Watchtower](https://community.topcoder.com/stat?c=problem_statement&pm=2014&rd=4685)
## Sweep Line
### Tutorial
- CPH 30
- [TopCoder Line Sweep](https://www.topcoder.com/community/competitive-programming/tutorials/line-sweep-algorithms/)
### Problems
- [Cow Steepchase II (Silver)](http://www.usaco.org/index.php?page=viewproblem2&cpid=943)
- :|
- [Kattis Closest Pair](https://open.kattis.com/problems/closestpair2)
## Convex Hull
## [Convex Hull](https://en.wikipedia.org/wiki/Convex_hull_algorithms)
- [Kattis Convex Hull](https://open.kattis.com/problems/convexhull)
@ -49,55 +78,19 @@ You should know basic operations like cross product and dot product. For platinu
- [USACO Plat Falling](http://www.usaco.org/index.php?page=viewproblem2&cpid=998)
- [USACO Old Gold - Fencing](http://www.usaco.org/index.php?page=viewproblem2&cpid=534)
- [USACO Old Gold - Cow Curling](http://www.usaco.org/index.php?page=viewproblem2&cpid=382)
- [Kattis Fence Orthogonality](https://open.kattis.com/problems/fenceortho)
- [AGC 44 Random Pawn](https://atcoder.jp/contests/agc044/tasks/agc044_e)
- Generalization of "Balance"
(old)
## Half-Plane Intersection / Convex Stuff
- [Blogewoosh (Half-Plane Intersection w/ Ternary Search)](https://codeforces.com/blog/entry/61710)
- [retrograd Half-Plane Intersection](https://codeforces.com/blog/entry/61710?#comment-457662)
- [Petr (Linear Half-Plane Intersection)](https://petr-mitrichev.blogspot.com/2016/07/a-half-plane-week.html)
- [KACTL LineContainer](https://github.com/kth-competitive-programming/kactl/blob/master/content/data-structures/LineContainer.h)
- [Lichao Segment Tree](http://codeforces.com/blog/entry/51275?#comment-351510)
[CPC.12](https://github.com/SuprDewd/T-414-AFLV/tree/master/12_geometry)
### Problems
## 4
* Misc Stuff to Know
* Topics
* std::complex, pair operators
* Closest Pair
* MaxCollinear
* Point in Polygon
* Polygon Area
* Line Segment Intersection
* Tutorial
* [TopCoder](https://www.topcoder.com/community/data-science/data-science-tutorials/geometry-concepts-basic-concepts/)
* [Point Class](http://codeforces.com/blog/entry/48122)
* [Easy Geo w/ std::complex](http://codeforces.com/blog/entry/22175)
* [Geo Book](http://codeforces.com/blog/entry/59129)
* CPH (29, Geometry)
* Problems
* [Arpa & Geo](http://codeforces.com/problemset/problem/851/B)
* [Tell Your World](http://codeforces.com/problemset/problem/849/B)
* [Gleb & Pizza](http://codeforces.com/problemset/problem/842/B)
* [Birthday Cake](https://open.kattis.com/problems/birthdaycake)
* [Racing Off Track](https://open.kattis.com/contests/acpc17open/problems/racingofftrack)
* [TopCoder Watchtower](https://community.topcoder.com/stat?c=problem_statement&pm=2014&rd=4685)
* Convex Hull
* Tutorial
* CPH (30, Sweep Line Algorithms)
* [TopCoder Line Sweep](https://www.topcoder.com/community/data-science/data-science-tutorials/line-sweep-algorithms/)
* Topics
* Convex Hull
* [Wikipedia](https://en.wikipedia.org/wiki/Convex_hull_algorithms)
* Andrew's Monotone Chain (I prefer)
* Graham Scan
* Additional
* [Lichao Segment Tree](http://codeforces.com/blog/entry/51275?#comment-351510)
* Half-Plane Intersection
* [Blogewoosh (Ternary Search)](https://codeforces.com/blog/entry/61710)
* [retrograd](https://codeforces.com/blog/entry/61710?#comment-457662)
* [Petr (Linear](https://petr-mitrichev.blogspot.com/2016/07/a-half-plane-week.html)
* LineContainer
* maintaining separate ones for bottom and top hulls should suffice?
* Problem(s)
* [Bridges](https://csacademy.com/contest/archive/task/building-bridges/)
* [Fence Orthogonality](https://open.kattis.com/problems/fenceortho)
* [A2OJ](https://a2oj.com/category?ID=22)
- [Bridges](https://csacademy.com/contest/archive/task/building-bridges/)
- direct application of LineContainer

View file

@ -18,7 +18,6 @@ Note: all except the third have not appeared on a recent USACO contest.
*Some problems sourced from [here](http://codeforces.com/blog/entry/54526?#comment-385354).*
## Eulerian Tours
Has not appeared on a recent USACO contest.

View file

@ -180,5 +180,5 @@ Again, the intended solution runs in $O(N^3)$. Of course, it is still possible t
Using operations such as `_Find_first()` and `_Find_next()` mentioned in Errichto's blog above, you can speed up the following:
* BFSing through a dense graph with $N$ vertices in $O(N^2)$
* bipartite matching in $O(N^3)$
- BFSing through a dense graph with $N$ vertices in $O(N^2)$
- bipartite matching in $O(N^3)$

View file

@ -295,6 +295,7 @@ int main() {
## Other Problems
- [Baltic OI 2019 - Olympiads](https://cses.fi/248/submit/D)
- [Baltic OI 2019 - Olympiads](https://cses.fi/248/list/)
- Each state has $\le K$ children.
- [CCO 20 Shopping Plans](https://dmoj.ca/problem/cco20p6)
- Generalization of Robotic Cow Herd

View file

@ -190,15 +190,18 @@ int main() {
## Problems
- [Moving Haybales (USACO Camp)](https://probgate.org/viewproblem.php?pid=247)
- similar to "Potatoes"
- [Wall](https://atcoder.jp/contests/kupc2016/tasks/kupc2016_h)
- same as "Potatoes"
- [Stock Trading (USACO Camp)](https://probgate.org/viewproblem.php?pid=531&cid=81)
- extension of "Buy Low Sell High"
- [Bookface](https://codeforces.com/group/ZFgXbZSjvp/contest/274852/problem/C)
- [Bookface](https://codeforces.com/gym/102576/problem/C)
- [CCDSAP Exam](https://www.codechef.com/problems/CCDSAP)
- basically same as Bookface
- [Farm of Monsters](https://codeforces.com/gym/102538/problem/F)
- [Moving Walkways](https://codeforces.com/contest/1209/problem/H)
- [April Fools' Problem](https://codeforces.com/contest/802/problem/O)
- binary search on top of slope trick
- [Conquer the World](https://icpc.kattis.com/problems/conquertheworld)
- note: ICPC world finals, 0 solves in contest
- ICPC world finals, 0 solves in contest
- "Potatoes" on tree!!