diff --git a/additionalContent/Running_Cpp.mdx b/additionalContent/Running_Cpp.mdx index cfbad0f..8557a61 100644 --- a/additionalContent/Running_Cpp.mdx +++ b/additionalContent/Running_Cpp.mdx @@ -80,6 +80,7 @@ Vim is probably the easiest way to print syntax-highlighted code on Mac, see the ### Sublime Text Notes (Ben) - I prefer the **Mariana** color scheme in place of the default. + - open command palette (Cmd-Shift-P) -> change color scheme - [`subl` 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. - [Snippets](https://www.granneman.com/webdev/editors/sublime-text/top-features-of-sublime-text/quickly-insert-text-and-code-with-sublime-text-snippets) diff --git a/content/3_Bronze/Intro_DS.mdx b/content/3_Bronze/Intro_DS.mdx index 4669679..c47c72d 100644 --- a/content/3_Bronze/Intro_DS.mdx +++ b/content/3_Bronze/Intro_DS.mdx @@ -22,8 +22,8 @@ export const metadata = { module is based off this - - ow dynamic arrays work + vectors, strings + how dynamic arrays work assumes prior experience diff --git a/content/3_Bronze/Rect_Geo.mdx b/content/3_Bronze/Rect_Geo.mdx index 65e8083..286980f 100644 --- a/content/3_Bronze/Rect_Geo.mdx +++ b/content/3_Bronze/Rect_Geo.mdx @@ -8,20 +8,20 @@ frequency: 2 import { Problem } from "../models"; export const metadata = { - problems: { - blocked: [ - new Problem("Bronze", "Blocked Billboard", "759", "Easy", false, ["rect"]), - ], - general: [ + problems: { + blocked: [ + new Problem("Bronze", "Blocked Billboard", "759", "Easy", false, ["rect"]), + ], + general: [ new Problem("Bronze", "Square Pasture", "663", "Very Easy", false, ["rect"]), new Problem("Bronze", "Blocked Billboard II", "783", "Easy", false, ["rect"]), new Problem("CF", "Div. 3 C - White Sheet", "contest/1216/problem/C", "Normal", false, ["rect"],"See this code (TODO; codeforces is down) for a nice implementation using the Java Rectangle class."), - ] - } + ] + } }; - module is based off this + module is based off this
@@ -78,7 +78,7 @@ Of course, this wouldn't suffice if the coordinates were up to $10^9$. ### Rectangle Class -A useful class in `Java` for dealing with rectangle geometry problems (though definitely overkill) is the built-in [`Rectangle`](https://docs.oracle.com/javase/8/docs/api/java/awt/Rectangle.html) class. +A useful class in Java for dealing with rectangle geometry problems (though definitely overkill) is the built-in [`Rectangle`](https://docs.oracle.com/javase/8/docs/api/java/awt/Rectangle.html) class. @@ -93,11 +93,11 @@ Rectangle newRect = new Rectangle(x, y, width, height); The `Rectangle` class supports numerous useful methods. - - `firstRect.intersects(secondRect)` checks if two rectangles intersect. - - `firstRect.union(secondRect)` returns a rectangle representing the union of two rectangles. - - `firstRect.contains(x, y)` checks whether the integer point $(x,y)$ exists in firstRect. - - `firstRect.intersection(secondRect)` returns a rectangle representing the intersection of two rectangles. - - what happens when intersection is empty? + - `firstRect.intersects(secondRect)` checks if two rectangles intersect. + - `firstRect.union(secondRect)` returns a rectangle representing the union of two rectangles. + - `firstRect.contains(x, y)` checks whether the integer point $(x,y)$ exists in firstRect. + - `firstRect.intersection(secondRect)` returns a rectangle representing the intersection of two rectangles. + - what happens when intersection is empty? This class can often lessen the implementation needed in a lot of bronze problems and CodeForces problems. @@ -111,29 +111,29 @@ import java.io.*; import java.util.*; public class blockedBillboard { - public static void main(String[] args) throws IOException{ - Scanner sc = new Scanner(new File("billboard.in")); - PrintWriter pw = new PrintWriter(new FileWriter("billboard.out")); - int x1, y1, x2, y2; + public static void main(String[] args) throws IOException{ + Scanner sc = new Scanner(new File("billboard.in")); + PrintWriter pw = new PrintWriter(new FileWriter("billboard.out")); + int x1, y1, x2, y2; - // the top left point is (0,0), so you need to do -y2 - x1 = sc.nextInt(); y1 = sc.nextInt(); x2 = sc.nextInt(); y2 = sc.nextInt(); - Rectangle firstRect = new Rectangle(x1, -y2, x2-x1, y2-y1); - x1 = sc.nextInt(); y1 = sc.nextInt(); x2 = sc.nextInt(); y2 = sc.nextInt(); - Rectangle secondRect = new Rectangle(x1, -y2, x2-x1, y2-y1); - x1 = sc.nextInt(); y1 = sc.nextInt(); x2 = sc.nextInt(); y2 = sc.nextInt(); - Rectangle truck = new Rectangle(x1, -y2, x2-x1, y2-y1); + // the top left point is (0,0), so you need to do -y2 + x1 = sc.nextInt(); y1 = sc.nextInt(); x2 = sc.nextInt(); y2 = sc.nextInt(); + Rectangle firstRect = new Rectangle(x1, -y2, x2-x1, y2-y1); + x1 = sc.nextInt(); y1 = sc.nextInt(); x2 = sc.nextInt(); y2 = sc.nextInt(); + Rectangle secondRect = new Rectangle(x1, -y2, x2-x1, y2-y1); + x1 = sc.nextInt(); y1 = sc.nextInt(); x2 = sc.nextInt(); y2 = sc.nextInt(); + Rectangle truck = new Rectangle(x1, -y2, x2-x1, y2-y1); - long firstIntersect = getArea(firstRect.intersection(truck)); - long secondIntersect = getArea(secondRect.intersection(truck)); - pw.println(getArea(firstRect)+getArea(secondRect) - - firstIntersect - secondIntersect); - pw.close(); - } - public static long getArea(Rectangle r){ - if (r.isEmpty()) return 0; - return (long)r.getHeight()*(long)r.getWidth(); - } + long firstIntersect = getArea(firstRect.intersection(truck)); + long secondIntersect = getArea(secondRect.intersection(truck)); + pw.println(getArea(firstRect)+getArea(secondRect) + - firstIntersect - secondIntersect); + pw.close(); + } + public static long getArea(Rectangle r){ + if (r.isEmpty()) return 0; + return (long)r.getHeight()*(long)r.getWidth(); + } } ``` @@ -145,28 +145,28 @@ import java.io.*; import java.util.*; class Rect { - int x1, y1, x2, y2; - Rect() {} + int x1, y1, x2, y2; + Rect() {} + int area() { return (y2-y1)*(x2-x1); } } public class blockedBillboard { - public static void main (String[] args) throws IOException{ - Scanner sc = new Scanner(new File("billboard.in")); - PrintWriter pw = new PrintWriter(new FileWriter("billboard.out")); - Rect a = new Rect(), b = new Rect(), t = new Rect(); - int x1, y1, x2, y2; - a.x1 = sc.nextInt(); a.y1 = sc.nextInt(); a.x2 = sc.nextInt(); a.y2 = sc.nextInt(); - b.x1 = sc.nextInt(); b.y1 = sc.nextInt(); b.x2 = sc.nextInt(); b.y2 = sc.nextInt(); - t.x1 = sc.nextInt(); t.y1 = sc.nextInt(); t.x2 = sc.nextInt(); t.y2 = sc.nextInt(); - pw.println(area(a) + area(b) - intersect(a, t) - intersect(b, t)); - pw.close(); - } - static int area(Rect r){ return (r.y2 - r.y1) * (r.x2 - r.x1); } - static int intersect(Rect p, Rect q) { - int xOverlap = Math.max(0, Math.min(p.x2, q.x2) - Math.max(p.x1, q.x1)); - int yOverlap = Math.max(0, Math.min(p.y2, q.y2) - Math.max(p.y1, q.y1)); - return xOverlap * yOverlap; - } + public static void main (String[] args) throws IOException{ + Scanner sc = new Scanner(new File("billboard.in")); + PrintWriter pw = new PrintWriter(new FileWriter("billboard.out")); + Rect a = new Rect(), b = new Rect(), t = new Rect(); + int x1, y1, x2, y2; + a.x1 = sc.nextInt(); a.y1 = sc.nextInt(); a.x2 = sc.nextInt(); a.y2 = sc.nextInt(); + b.x1 = sc.nextInt(); b.y1 = sc.nextInt(); b.x2 = sc.nextInt(); b.y2 = sc.nextInt(); + t.x1 = sc.nextInt(); t.y1 = sc.nextInt(); t.x2 = sc.nextInt(); t.y2 = sc.nextInt(); + pw.println(a.area()+b.area()-intersect(a, t)-intersect(b, t)); + pw.close(); + } + static int intersect(Rect p, Rect q) { + int xOverlap = Math.max(0, Math.min(p.x2, q.x2) - Math.max(p.x1, q.x1)); + int yOverlap = Math.max(0, Math.min(p.y2, q.y2) - Math.max(p.y1, q.y1)); + return xOverlap * yOverlap; + } } ``` @@ -175,41 +175,33 @@ public class blockedBillboard { -Unfortunately, C++ doesn't have a built in rectangle class, so you need to write the functions yourself. Here is the solution to Blocked Billboard written in C++ (thanks, Brian Dean!). +Unfortunately, C++ doesn't have a built in rectangle class, so you need to write the functions yourself. Here is the solution to Blocked Billboard written in C++ (thanks, Brian Dean!). A C++ [`struct`](http://www.cplusplus.com/doc/tutorial/structures/) is the same as a C++ `class` but all members are `public` rather than `private` by default. ```cpp -#include -#include +#include using namespace std; -struct Rect{ - int x1, y1, x2, y2; +struct Rect { + int x1,y1,x2,y2; + int area() { return (y2-y1)*(x2-x1); } }; - -int area(Rect r){ - return (r.y2 - r.y1) * (r.x2 - r.x1); -} - int intersect(Rect p, Rect q){ - int xOverlap = max(0, min(p.x2, q.x2) - max(p.x1, q.x1)); - int yOverlap = max(0, min(p.y2, q.y2) - max(p.y1, q.y1)); - return xOverlap * yOverlap; + int xOverlap = max(0,min(p.x2,q.x2)-max(p.x1,q.x1)); + int yOverlap = max(0,min(p.y2,q.y2)-max(p.y1,q.y1)); + return xOverlap*yOverlap; } int main(){ ifstream cin ("billboard.in"); ofstream cout ("billboard.out"); - Rect a, b, t; // billboards a, b, and the truck - cin >> a.x1 >> a.y1 >> a.x2 >> a.y2; - cin >> b.x1 >> b.y1 >> b.x2 >> b.y2; - cin >> t.x1 >> t.y1 >> t.x2 >> t.y2; - - cout << area(a) + area(b) - intersect(a, t) - intersect(b, t) << endl; - return 0; + Rect a, b, t; // billboards a, b, and the truck + cin >> a.x1 >> a.y1 >> a.x2 >> a.y2; + cin >> b.x1 >> b.y1 >> b.x2 >> b.y2; + cin >> t.x1 >> t.y1 >> t.x2 >> t.y2; + cout << a.area()+b.area()-intersect(a,t)-intersect(b,t) << endl; } - ``` diff --git a/content/3_Bronze/Simulation.mdx b/content/3_Bronze/Simulation.mdx index 5a15d84..ee9758c 100644 --- a/content/3_Bronze/Simulation.mdx +++ b/content/3_Bronze/Simulation.mdx @@ -35,7 +35,7 @@ export const metadata = {
-Since there's no formal algorithm involved, the intent of the problem is to assess competence with one's programming language of choice and knowledge of built-in data structures. At least in USACO Bronze, when a problem statement says to find the end result of some process, or to find when something occurs, it's usually sufficient to **simulate** the process naively. +Since there's no formal algorithm involved, the intent of the problem is to assess competence with one's programming language of choice and knowledge of built-in data structures. At least in USACO Bronze, when a problem statement says to find the end result of some process, or to find when something occurs, it's usually sufficient to simulate the process naively. ## Example 1 diff --git a/content/4_Silver/Binary_Search_Ans.mdx b/content/4_Silver/Binary_Search_Ans.mdx index 1de6732..d2601df 100644 --- a/content/4_Silver/Binary_Search_Ans.mdx +++ b/content/4_Silver/Binary_Search_Ans.mdx @@ -4,7 +4,7 @@ title: "Binary Search on the Answer" author: Darren Yao, Abutalib Namazov prerequisites: - Silver - Binary Search on a Sorted Array -description: You should already be familiar with the concept of binary searching for a number in a sorted array. However, binary search can be extended to binary searching on the answer itself. +description: "?" frequency: 3 --- diff --git a/content/4_Silver/Binary_Search_Sorted.mdx b/content/4_Silver/Binary_Search_Sorted.mdx index 4ae9f56..4093319 100644 --- a/content/4_Silver/Binary_Search_Sorted.mdx +++ b/content/4_Silver/Binary_Search_Sorted.mdx @@ -5,7 +5,7 @@ author: Siyong Huang, Michael Cao, Nathan Chen description: "?" prerequisites: - Bronze - Introduction to Data Structures -frequency: 4 +frequency: 2 --- import { Problem } from "../models"; diff --git a/content/4_Silver/Custom_Cpp_STL.mdx b/content/4_Silver/Custom_Cpp_STL.mdx index ba030bd..ffccdba 100644 --- a/content/4_Silver/Custom_Cpp_STL.mdx +++ b/content/4_Silver/Custom_Cpp_STL.mdx @@ -19,7 +19,9 @@ What if we want to use a C++ `set` with the `Edge` struct that was defined in "S ## Operator Overloading -Works as expected, although you should make sure to include the second `const` or you'll get a compilation error. (explain meaning of this) +Works as expected, although you should make sure to include the second `const` or you'll get a compilation error. From the link above: + +> [The second const] means you cannot modify member variables of the current object. ```cpp #include @@ -127,7 +129,7 @@ int main() { ## Built-In Functors -Overloading `<` automatically generates the functor `less`. Similarly, overloading `>` automatically generates the functor [`greater`](https://en.cppreference.com/w/cpp/utility/functional/greater). We can use this to store a set in reverse order. +Overloading the less than operator (`<`) automatically generates the functor `less`. Similarly, overloading `>` automatically generates the functor [`greater`](https://en.cppreference.com/w/cpp/utility/functional/greater). We can use this to store a set in reverse order. ```cpp #include diff --git a/content/4_Silver/Harder_Ordered.mdx b/content/4_Silver/Harder_Ordered.mdx index b35221c..72c3298 100644 --- a/content/4_Silver/Harder_Ordered.mdx +++ b/content/4_Silver/Harder_Ordered.mdx @@ -125,6 +125,8 @@ int main() { + + ## Problems diff --git a/content/4_Silver/Intro_Ordered.mdx b/content/4_Silver/Intro_Ordered.mdx index a27817b..aa35a4d 100644 --- a/content/4_Silver/Intro_Ordered.mdx +++ b/content/4_Silver/Intro_Ordered.mdx @@ -4,7 +4,7 @@ title: "Introduction to Ordered Sets" author: Darren Yao, Benjamin Qi prerequisites: - Bronze - Unordered Maps & Sets -description: "" +description: "?" frequency: 2 --- @@ -52,8 +52,6 @@ cout << *(--it) << '\n'; // 14 s.erase(s.upper_bound(6)); // [1, 2, 14] ``` -The primary limitation of the ordered set is that we can't efficiently access the $k^{th}$ largest element in the set, or find the number of elements in the set greater than some arbitrary $x$. These operations can be handled using a data structure called an order statistic tree (see Gold - Binary Indexed Trees). -
@@ -75,12 +73,12 @@ set.remove(set.higher(6)); // [1, 2, 14] System.out.println(set.higher(23); // ERROR, no such element exists ``` -One limitation of the ordered set is that we can't efficiently access the $k^{th}$ largest element in the set, or find the number of elements in the set greater than some arbitrary $x$. These operations can be handled using a data structure called an **order statistic tree** (see Gold - Point Update Range Sum). -
+One limitation of the ordered set is that we can't efficiently access the $k^{th}$ largest element in the set, or find the number of elements in the set greater than some arbitrary $x$. These operations can be handled using a data structure called an **order statistic tree** (see Gold - Point Update Range Sum). + ## Ordered Maps @@ -189,9 +187,27 @@ static void remove(int x){ - ## Using Iterators + + + + + +next(), prev(), ++, -- + + + + + + + + + + + + + ## Standard \ No newline at end of file diff --git a/content/4_Silver/Prefix_Sums.mdx b/content/4_Silver/Prefix_Sums.mdx index 0391394..f009ee2 100644 --- a/content/4_Silver/Prefix_Sums.mdx +++ b/content/4_Silver/Prefix_Sums.mdx @@ -43,7 +43,7 @@ export const metadata = { new Problem("CSES", "Range XOR Queries", "1650", "Easy", false, ["Prefix Sums"], "XOR prefix[r] with prefix[l-1]"), ], complex: [ - new Problem("Google Kick Start", "Candies (Test Set 1)", "https://codingcompetitions.withgoogle.com/kickstart/round/000000000019ff43/0000000000337b4d", "Easy", false, ["Prefix Sums"], ""), + new Problem("Google KickStart", "Candies (Test Set 1)", "https://codingcompetitions.withgoogle.com/kickstart/round/000000000019ff43/0000000000337b4d", "Easy", false, ["Prefix Sums"], ""), new Problem("AC", "Multiple of 2019", "https://atcoder.jp/contests/abc164/tasks/abc164_d", "Hard", false, ["Prefix Sums"], "Make use of the fact that adding 0's to the end of a number does not affect whether it is a multiple of 2019 (because 10 and 2019 are coprime)."), ], } @@ -395,7 +395,13 @@ $$ + \texttt{prefix}[a-1][b-1] $$ -Summing the blue region from above using the 2d prefix sums method, we add the value of the green square, subtract the values of the red squares, and then add the value of the gray square. In this example, we have $65-23-6+1 = 37$, as expected. +Summing the blue region from above using the 2D prefix sums method, we add the value of the green square, subtract the values of the red squares, and then add the value of the gray square. In this example, we have + +$$ +65-23-6+1 = 37, +$$ + +as expected.
@@ -446,7 +452,7 @@ Summing the blue region from above using the 2d prefix sums method, we add the v
-Since no matter the size of the submatrix we are summing, we only need to access four values of the 2d prefix sum array, this runs in $O(1)$ per query after an $O(NM)$ preprocessing. This is fast enough. +Since no matter the size of the submatrix we are summing, we only need to access four values of the 2D prefix sum array, this runs in $O(1)$ per query after an $O(NM)$ preprocessing. diff --git a/content/4_Silver/Sorting_Custom.mdx b/content/4_Silver/Sorting_Custom.mdx index 54b9d79..656bc79 100644 --- a/content/4_Silver/Sorting_Custom.mdx +++ b/content/4_Silver/Sorting_Custom.mdx @@ -105,8 +105,6 @@ First, we need to define a **class** that represents what we want to sort. In ou -A C++ [`struct`](http://www.cplusplus.com/doc/tutorial/structures/) is the same as a C++ `class` but all members are `public` rather than `private` by default. - ```cpp #include using namespace std;