From 5a1dcccae6e950478144967ab7a27e756e4a0023 Mon Sep 17 00:00:00 2001 From: summitwei Date: Wed, 17 Jun 2020 14:05:00 -0400 Subject: [PATCH 1/4] added some problems --- content/6_Plat/Trees.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/content/6_Plat/Trees.md b/content/6_Plat/Trees.md index 97a67fc..1f63681 100644 --- a/content/6_Plat/Trees.md +++ b/content/6_Plat/Trees.md @@ -64,6 +64,7 @@ Other: ### Problems + - [Ciel the Commander](https://codeforces.com/problemset/problem/321/C) - [USACO Plat - At Large](http://www.usaco.org/index.php?page=viewproblem2&cpid=793) - very tricky - [DMOJ Bob Equilibrium](https://dmoj.ca/problem/dmopc19c7p6) @@ -83,5 +84,6 @@ Other: ?? ## Small to Large (Offline) - -?? \ No newline at end of file +Sample codes: [DSU on Tree code](https://codeforces.com/blog/entry/44351), [explanation of code](https://codeforces.com/blog/entry/67696) + - USACO Disrupt again! + - [Lomsat gelral](https://codeforces.com/contest/600/problem/E) From bb202d94a6a3d3b10f426c641aa0d39c89843c3e Mon Sep 17 00:00:00 2001 From: Benjamin Qi Date: Wed, 17 Jun 2020 14:05:19 -0400 Subject: [PATCH 2/4] modify intro / general --- content/1_Intro/Getting_Started.md | 14 +-- content/1_Intro/Practicing.md | 6 +- content/1_Intro/Prerequisites.md | 13 ++- content/1_Intro/Running_Cpp.md | 74 ++++++------ content/2_General/Contest_Strategy.md | 22 +++- content/2_General/Contests.md | 159 +++++++++++++------------- content/2_General/Debugging.md | 8 +- content/2_General/Macros.md | 2 +- content/2_General/Proposing.md | 5 +- content/3_Bronze/Rect_Geo.md | 33 +++--- content/6_Plat/1DRQ.md | 2 +- 11 files changed, 183 insertions(+), 155 deletions(-) diff --git a/content/1_Intro/Getting_Started.md b/content/1_Intro/Getting_Started.md index d81d247..ca7145d 100644 --- a/content/1_Intro/Getting_Started.md +++ b/content/1_Intro/Getting_Started.md @@ -12,14 +12,14 @@ author: Nathan Wang, Benjamin Qi, Darren Yao ## Introduction -The goal of **competitive programming** is to write code to solve given problems "quickly." These problems are not open problems; they are problems that are designed to be solved in the short timeframe of a contest, and have already been solved by the problem writer(s) and tester(s). In general, each problem in competitive programming is solved by a two-step process: +A **programming competition** generally lasts for several hours and consists of a set of problems. These problems are not open problems; they have already been solved by the problem writer(s) and tester(s) and (hopefully) are designed to be solved in the short timeframe of a contest. In general, each problem in competitive programming is solved by a two-step process: 1. coming up with the algorithm, which involves problem solving skills and intuition 2. implementing the algorithm, which requires programming skills to translate the algorithm into working code. -A contest generally lasts for several hours and consists of a set of problems. For each problem, when you complete your code, you submit it to a grader, which checks the answers calculated by the your program against a set of predetermined test cases. For each problem, you are given a time limit (usually 2 seconds) and a memory limit (usually 256 megabytes) that your program must satisfy. +For each problem, when you complete your code you submit it to a grader, which checks the answers calculated by the your program against a set of predetermined test cases. For each problem, you are given a time limit (usually 2 seconds) and a memory limit (usually 256 megabytes) that your program must satisfy. -For those of you with experience in software development, note that competitive programming is quite different, as the goal is to write programs that compute the correct answer, run quickly, and can be implemented quickly. Note that nowhere was maintainability of code mentioned. This means that you should throw away everything you know about traditional code writing; you don't need to bother documenting your code, because it only needs to be readable to you, during the contest. +For those of you with experience in software development, note that competitive programming is quite different, as the goal is to write programs that compute the correct answer, run quickly, and can be implemented quickly. Note that nowhere was maintainability of code mentioned. So you don't need to bother documenting your code because it only needs to be readable to you during the contest. ### Videos @@ -29,11 +29,11 @@ For those of you with experience in software development, note that competitive ## Contest Format -The [USA Computing Olympiad](http://www.usaco.org/index.php?page=contests) is a national programming competition that occurs four times a year, with December, January, February, and US Open (March) contests. The regular contests are four hours long, and the US Open is five hours long. Each contest contains three problems. Solutions are evaluated and scored against a set of predetermined test cases that are not visible to the student. Scoring is out of 1000 points, with each problem being weighted equally. There are four divisions of contests: Bronze, Silver, Gold, and Platinum. After each contest, students who meet the contest-dependent cutoff for promotion will compete in the next division for future contests. +The [USA Computing Olympiad](http://www.usaco.org/index.php?page=contests) is a national programming competition that occurs four times a year, with December, January, February, and US Open (March) contests. The regular contests are four hours long, and the US Open is five hours long. Each contest contains three problems. Solutions are evaluated and scored against a set of predetermined test cases that are not visible to the student. Scoring is out of 1000 points, with each problem being weighted equally (\~333 points). There are four divisions of contests: Bronze, Silver, Gold, and Platinum. After each contest, students who meet the contest-dependent cutoff for promotion will compete in the next division for future contests. ## 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. +If you're in Bronze, **don't worry about the language!** If you already know a language, just use it. In general, we recommend the following: @@ -42,9 +42,7 @@ In general, we recommend the following: - For Silver, Gold, and Platinum, we recommend C++/Java. - If you know multiple languages, we recommend you pick C++ over Java. -Note: A majority of high level contestants use C++ and Java. Between those, C++ is more popular. - -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! +A majority of high level contestants use C++ and Java. Between those, C++ is more popular. 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! ### Language References diff --git a/content/1_Intro/Practicing.md b/content/1_Intro/Practicing.md index f9ae029..c0eb61d 100644 --- a/content/1_Intro/Practicing.md +++ b/content/1_Intro/Practicing.md @@ -95,4 +95,8 @@ I follow three guidelines (from most important to least important) ## Eric Wei -I think the most important thing regarding practicing is to try to get something out of every problem, whether it's a new algorithm or idea, an implementation trick that can help in the future, or just a bug you hopefully won't mess up in the future. That being said, editorials are more useful once you've been stuck for a while; I think the exploration that happens from being a little stuck is often instructive (and good practice for contests, when it's your only option). But at some point the problem's more frustrating than helpful, and sometime before this is probably the right time to take a hint or read the editorial. \ No newline at end of file +I think the most important thing regarding practicing is to try to get something out of every problem, whether it's a new algorithm or idea, an implementation trick that can help in the future, or just a bug you hopefully won't mess up in the future. That being said, editorials are more useful once you've been stuck for a while; I think the exploration that happens from being a little stuck is often instructive (and good practice for contests, when it's your only option). But at some point the problem's more frustrating than helpful, and sometime before this is probably the right time to take a hint or read the editorial. + +## Additional + + - [E869120 - A Way to Practice CP](http://codeforces.com/blog/entry/53341) \ No newline at end of file diff --git a/content/1_Intro/Prerequisites.md b/content/1_Intro/Prerequisites.md index 5b476ce..7dc69b1 100644 --- a/content/1_Intro/Prerequisites.md +++ b/content/1_Intro/Prerequisites.md @@ -1,7 +1,7 @@ --- id: prereqs title: Prerequisites -author: Nathan Wang +author: Nathan Wang, Benjamin Qi --- Here's what you should learn before reading these resources. @@ -37,9 +37,12 @@ Familiarity with [competition math](https://github.com/bqi343/USACO/blob/master/ ### Resources for Getting Started +Note: We don't agree with all views expressed in the links below. Feel free to let us know what works (or doesn't) for you. + - [CodeSignal](https://codesignal.com/) - - good place to practice basics - - [IOI: Getting Started](https://ioinformatics.org/page/getting-started/14) + - can practice basics with "Arcade," "Interview Practice" - [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) \ No newline at end of file + - lots of links! + - [IOI - Getting Started](https://ioinformatics.org/page/getting-started/14) + - not so up to date + - [Quora - Schedule for Beginners (Joshua Pan)](https://www.quora.com/What-is-a-good-schedule-to-follow-for-becoming-better-at-competitive-programming-for-beginners) \ No newline at end of file diff --git a/content/1_Intro/Running_Cpp.md b/content/1_Intro/Running_Cpp.md index 7dfbca0..d5249f6 100644 --- a/content/1_Intro/Running_Cpp.md +++ b/content/1_Intro/Running_Cpp.md @@ -10,29 +10,29 @@ Running C++ both online and locally. # Running C++ Online - * [OnlineGDB](https://www.onlinegdb.com/) - * online compiler with an embedded GDB debugger - * can be buggy sometimes - * supports files and file I/O - * [CSAcademy](https://csacademy.com/workspace/) - * pretty nice (unless you get "Estimated Queue Time: ...") - * "saved locally" will not save your code if you close the tab, press Command-S to save. - * [Ideone](http://ideone.com/) - * okay ... with an ad blocker - * make sure your code is not public - * sometimes erases your code when you first create it (so get in the habit of copying your code first) + - [OnlineGDB](https://www.onlinegdb.com/) + - online compiler with an embedded GDB debugger + - can be buggy sometimes + - supports files and file I/O + - [CSAcademy](https://csacademy.com/workspace/) + - pretty nice (unless you get "Estimated Queue Time: ...") + - "saved locally" will not save your code if you close the tab, press Command-S to save. + - [Ideone](http://ideone.com/) + - okay ... with an ad blocker + - make sure your code is not public + - sometimes erases your code when you first create it (so get in the habit of copying your code first) -Of course, you can't use file I/O on the latter two websites and they are often quite limited. +Of course, you can't use file I/O on the latter two websites. # Running C++ Locally ## On Mac -[Clang](https://en.wikipedia.org/wiki/Clang) is the default compiler for Mac OS X, but you should use GCC's [g++](https://en.wikipedia.org/wiki/GNU_Compiler_Collection). +[Clang](https://en.wikipedia.org/wiki/Clang) is the default compiler for Mac OS X, but you should use [GCC](https://en.wikipedia.org/wiki/GNU_Compiler_Collection)'s g++. ### Installation -Open **Terminal**. First, familiarize yourself with some basic commands given [here](https://blog.teamtreehouse.com/introduction-to-the-mac-os-x-command-line). You will also need to install [Homebrew](https://brew.sh/). +First, Open **Terminal**. Familiarize yourself with some basic commands given [here](https://blog.teamtreehouse.com/introduction-to-the-mac-os-x-command-line). You will also need to install [Homebrew](https://brew.sh/). Run @@ -181,28 +181,32 @@ Note that all occurrences of `$1` are replaced with `name`. ## IDEs - * [Geany](https://www.geany.org/) - * [Visual Studio Code](https://code.visualstudio.com/) - * lightweight, fast IDE, but requires some configuration - * [Visual Studio](https://visualstudio.microsoft.com/vs/) - * heavier cousin of Visual Studio Code - * [XCode](https://developer.apple.com/xcode/) - * Mac only - * [Codeblocks](http://www.codeblocks.org/) - * bad on Mac - * [CLion](https://www.jetbrains.com/clion/) - * requires a license, but [free for students](https://www.jetbrains.com/community/education/#students) + - [Geany](https://www.geany.org/) + - [Visual Studio Code](https://code.visualstudio.com/) + - lightweight, fast IDE, but requires some configuration + - [Visual Studio](https://visualstudio.microsoft.com/vs/) + - heavier cousin of Visual Studio Code + - [XCode](https://developer.apple.com/xcode/) + - Mac only + - [Codeblocks](http://www.codeblocks.org/) + - bad on Mac + - [CLion](https://www.jetbrains.com/clion/) + - requires a license, but [free for students](https://www.jetbrains.com/community/education/#students) ## Text Editors -Again, many options. - * [Sublime Text 3](https://www.sublimetext.com/) - a fast, lightweight text editor for Windows, Mac, and Linux - * [Editing Build Settings](https://stackoverflow.com/questions/23789410/how-to-edit-sublime-text-build-settings) - * [FastOlympicCoding Addon](https://github.com/Jatana/FastOlympicCoding) - * [Sublime Snippets](https://www.granneman.com/webdev/editors/sublime-text/top-features-of-sublime-text/quickly-insert-text-and-code-with-sublime-text-snippets) - * [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/) - another text editor for Windows, Mac, and Linux, from the makers of Github - * [Vim](https://www.vim.org/) - the classic text editor, usually preinstalled on Mac and Linux, and also available for Windows - * Others? + + - [Sublime Text 3](https://www.sublimetext.com/) + - a fast, lightweight text editor for Windows, Mac, and Linux + - [Editing Build Settings](https://stackoverflow.com/questions/23789410/how-to-edit-sublime-text-build-settings) + - [FastOlympicCoding Addon](https://github.com/Jatana/FastOlympicCoding) + - [Sublime Snippets](https://www.granneman.com/webdev/editors/sublime-text/top-features-of-sublime-text/quickly-insert-text-and-code-with-sublime-text-snippets) + - [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/) + - another text editor for Windows, Mac, and Linux, from the makers of Github + - [Vim](https://www.vim.org/) + - the classic text editor, usually preinstalled on Mac and Linux, and also available for Windows + - probably easiest way to print syntax-highlighted code on Mac, see [here](https://stackoverflow.com/questions/1656914/printing-code-with-syntax-highlighting) + - Others? diff --git a/content/2_General/Contest_Strategy.md b/content/2_General/Contest_Strategy.md index 584ba7b..6258978 100644 --- a/content/2_General/Contest_Strategy.md +++ b/content/2_General/Contest_Strategy.md @@ -4,7 +4,11 @@ title: Contest Strategy author: Nathan Chen --- -The best contest strategy is to go in knowing everything. However, only few people can do this (see [BenQ](https://codeforces.com/profile/benq) or [TMW](https://codeforces.com/profile/tmwilliamlin168)) (I kid). Once the timer starts, there's no more studying you can do, and managing your time wisely is the best thing you can do to maximize your score. +The best contest strategy is to go in knowing everything. However, only few people can do this, see [BenQ](https://codeforces.com/profile/benq) or [TMW](https://codeforces.com/profile/tmwilliamlin168). (I kid). + + + +Once the timer starts, there's no more studying you can do, and managing your time wisely is the best thing you can do to maximize your score. ## Strategy @@ -12,28 +16,36 @@ Below are some general ideas on how to strategize during a contest. Strategy is flexible and all advice should be taken with a grain of salt. Strategy should be personal to *you* specifically. ### The beginning of a contest + You should read *all* the problems first (don't give up on any problems prematurely). Generally, a lot of thinking should happen before any coding. Depending on the difficulty of a contest, you can spend anywhere from 5 minutes to 2 hours with a pencil and paper before touching the keyboard. -Sometimes, problem difficulties can be out of order, so keep that in mind before focusing down 3 hours on problem 1 and not getting anywhere. Do a good amount of thinking on each problem before deciding which ones to focus on and which to put aside. +Problem difficulties can be out of order, so keep that in mind before focusing down 3 hours on problem 1 and not getting anywhere. Do a good amount of thinking on each problem before deciding which ones to focus on and which to put aside. ### Time allocation + It's the worst feeling in the world to sink 4 hours into a problem and not get it, only for another problem to have an easier solution. You have to use your own judgement in deciding what is likely solvable and what should be quit. Generally, don't spend "too long" on one problem, and stay away from problems that look like they test something you don't know well. ### When you see a solution + If you immediately get the solution to a problem while reading it, it might be a good idea to code it up quickly and get it out of the way. It also might be a good idea to make some progress on other problems before coding the one you know how to do. When you come back and start coding, you can make sure your solution still makes sense and then you have ideas from the other problems bouncing around in your head while you're coding. ### When there are partials + If you can get points from partially solving a problem (e.g. in USACO), then it's a good idea to keep those subtasks in mind. There are two main approaches to partially solving problems. + - Use most of your time to think about the full problem, then code the partials if you haven't found the solution and your time will soon run out. - If you find the full solution, be certain your solution is correct, lest you waste an hour coding something completely wrong. - - Judge the difficulty of the partials carefully! It could take anywhere from 30 seconds 30 minutes to code a partial, or maybe a partial wasn't as trivial as you thought! + - Judge the difficulty of the partials carefully! It could take anywhere from 30 seconds to 30 minutes to code a partial, or maybe a partial wasn't as trivial as you thought! - Work up from the partials, coding the easiest and then going to the hardest. The partial subtasks may help you think of the full solution, and will also help you stay on track. ## Personal Commentaries + ### Nathan Chen + At the Platinum level, I first read everything and then I usually spend the first hour thinking about the easiest two problems (the hardest problem is usually VERY hard). I continue thinking for the rest of the contest window and I code them if I think I have the solution. I'm also the type to save partials for last, when time is running out and I still have nothing. -### Anther Person -Somethign something +### Benjamin Qi + +Do the partials you can; hopefully by then you've figured out the full solution. :D \ No newline at end of file diff --git a/content/2_General/Contests.md b/content/2_General/Contests.md index 0d676c6..4df0d74 100644 --- a/content/2_General/Contests.md +++ b/content/2_General/Contests.md @@ -4,102 +4,103 @@ title: Contests author: Benjamin Qi --- -Contests that I participate in, as well as a few tools. +Contests that I participate in as well as a few tools. -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. +See [clist.by](https://clist.by/coder/bqi343/) for an extensive list of contests. -Make sure to [upsolve](https://en.wiktionary.org/wiki/upsolve) after the contest ends! I particularly enjoy problems from AtCoder and CSAcademy. :) +Make sure to [upsolve](https://en.wiktionary.org/wiki/upsolve) after the contest ends! - * [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 - * Solutions only tested after contest! - * [Don Mills OJ](http://dmoj.ca/) - * at least one contest every month during school year - * [Google Kickstart](https://codingcompetitions.withgoogle.com/kickstart) - * Feb - Nov - * [Kattis](https://open.kattis.com/) - * random ICPC stuff - * [HackerEarth](http://hackerearth.com/) - * Monthly "Easy" - * quality is not always good - * [Codechef](http://codechef.com/) - * Lunchtime, Cookoff - * quality is not always good + - [AtCoder](https://beta.atcoder.jp/contests/archive) + - probably the highest quality, although difficulty isn't always reasonable + - 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 + - Solutions only tested after contest! + - [Don Mills OJ](http://dmoj.ca/) + - at least one contest every month during school year + - [Google Kickstart](https://codingcompetitions.withgoogle.com/kickstart) + - Feb - Nov + - [Kattis](https://open.kattis.com/) + - misc ICPC contests + - [HackerEarth](http://hackerearth.com/) + - Monthly "Easy" + - quality is not always good + - [Codechef](http://codechef.com/) + - Lunchtime, Cookoff + - quality is not always good 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. :D - * [HackerRank](https://www.hackerrank.com/dashboard) + - [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. :D + - [HackerRank](https://www.hackerrank.com/dashboard) ## 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 + - [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 ## 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) - * [PClassic (Philadelphia)](https://pclassic.org/) - * Java only :(( - * [mBIT (Montgomery Blair HS)](https://mbit.mbhs.edu/) + - [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) + - [PClassic (Philadelphia)](https://pclassic.org/) + - Java only :(( + - [mBIT (Montgomery Blair HS)](https://mbit.mbhs.edu/) ## 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 + - [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) - * [CSAcademy 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/) + - [2D Geo Visualizer](https://codeforces.com/blog/entry/70330) + - [CSAcademy 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/) diff --git a/content/2_General/Debugging.md b/content/2_General/Debugging.md index 7674872..5b38421 100644 --- a/content/2_General/Debugging.md +++ b/content/2_General/Debugging.md @@ -10,7 +10,7 @@ Detecting issues within your program and figuring out how to avoid them in the f ## Style Guide -[Swift](https://codeforces.com/blog/entry/64218) +[Competitive C++ Manifesto: A Style Guide](https://codeforces.com/blog/entry/64218) ## Compilation @@ -27,6 +27,8 @@ See [here](https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html). `-Wall -Wextra -Wshadow` +[Variable shadowing](https://en.wikipedia.org/wiki/Variable_shadowing) should be avoided whenever possible. + ### Stack Size According to [this comment](https://codeforces.com/blog/entry/60999?#comment-449312), `-Wl,-stack_size -Wl,0xF0000000` increases the stack size on Mac (otherwise, you might get a runtime error). @@ -75,11 +77,9 @@ In essense, a debugger is a tool to "trace code" for you. It is not much differe Pros of using a debugger: - No need to write print statements so you save time - - You can step through the code in real time Cons of using a debugger: - - You cannot see the overall "output" of your program at each stage. For example, if I wanted to see the every single value of `i` in the program, I could not using a debugger. - + - You cannot see the overall "output" of your program at each stage. For example, if I wanted to see every single value of `i` in the program, I could not using a debugger. - Most advanced competitive programmers do not use debuggers; it is quite time inefficient. diff --git a/content/2_General/Macros.md b/content/2_General/Macros.md index 6d71dc4..dfe28f4 100644 --- a/content/2_General/Macros.md +++ b/content/2_General/Macros.md @@ -74,7 +74,7 @@ Most USACO problems satisfy $N\le 2\cdot 10^5$. 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. Uuse `rng()` instead. +See [neal's blog](https://codeforces.com/blog/entry/61587) about why `rand()` is bad. Use `rng()` instead. ### ckmin diff --git a/content/2_General/Proposing.md b/content/2_General/Proposing.md index 1f97b56..c63f07d 100644 --- a/content/2_General/Proposing.md +++ b/content/2_General/Proposing.md @@ -10,9 +10,8 @@ Anyone can propose problems for monthly contests. Email your proposal to Professor Dean. In the [past](http://www.usaco.org/index.php?page=viewproblem2&cpid=817), contestants have even written problems for their own divisions! -All problems should have 10 test cases at minimum (I believe that the maximum was 21 for [valleys](http://www.usaco.org/index.php?page=viewproblem2&cpid=950)). - -All statements must eventually be converted to the following format; please save us time by following it as best you can. + - All problems should have 10 test cases at minimum (I believe that the maximum was 21 for [valleys](http://www.usaco.org/index.php?page=viewproblem2&cpid=950)). You do not need to include these in your proposal. + - All statements must eventually be converted to the following format. It's not required, but please save us time by following it as best you can.
diff --git a/content/3_Bronze/Rect_Geo.md b/content/3_Bronze/Rect_Geo.md index af67149..fe8eff2 100644 --- a/content/3_Bronze/Rect_Geo.md +++ b/content/3_Bronze/Rect_Geo.md @@ -12,7 +12,8 @@ author: Darren Yao, Michael Cao - Also, the coordinates typically only go up to $1000$, so a program that performs $\approx 1000^2$ operations (ex. with a nested loop) should pass. ## Rectangle Class (Java) -A useful class in `Java` for dealing with rectangle geometry problems is the built-in `Rectangle` class. To create a new rectangle, use the following constructor: + +A useful class in `Java` for dealing with rectangle geometry problems is the built-in [`Rectangle`](https://docs.oracle.com/javase/8/docs/api/java/awt/Rectangle.html) class. To create a new rectangle, use the following constructor: ```java //creates a rectangle with upper-left corner at (x,y) with a specified width and height @@ -21,22 +22,21 @@ Rectangle newRect = new Rectangle(x, y, width, height); The `Rectangle` class supports numerous useful methods. -``` -firstRect.intersects(secondRect) checks if two rectangles intersect. + - `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.intersect(secondRect)`: returns a rectangle representing the intersection of two rectangles. -firstRect.union(secondRect) returns a rectangle representing the union of two rectangles. +This class can often lessen the implementation needed in a lot of bronze problems and CodeForces problems. -firstRect.contains(x, y) checks whether the integer point (x,y) exists in firstRect. +For example, here is a nice implementation of the problem [Blocked Billboard](http://usaco.org/index.php?page=viewproblem2&cpid=759) ([editorial](http://www.usaco.org/current/data/sol_billboard_bronze_dec17.html)). -firstRect.intersect(secondRect) returns a rectangle representing the intersection of two rectangles. -``` +
-This class can often lessen the implementation needed in a lot of bronze problems and codeforces problems. - -For example, here is a nice implementation of the problem Blocked Billboard (see below). See the editorial [here](http://www.usaco.org/current/data/sol_billboard_bronze_dec17.html) for more information on the solution. +Java Solution ```java -import java.awt.Rectangle; //needed to use Rectangle class +import java.awt.Rectangle; //need to use Rectangle class public class BlockedBillboard{ public static void main(String[] args) throws IOException{ @@ -49,18 +49,23 @@ public class BlockedBillboard{ - getArea(firstRect.intersect(truck)) - getArea(secondRect.intersect(truck))); pw.close(); } - public static long getArea(Rectangle r){ return r.getHeight() * r.getWidth() } } ``` +
+ (someone test code pls) ## Rectangle Class (C++) 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!). +
+ +C++ Solution + ```cpp struct Rect{ int x1, y1, x2, y2; @@ -88,8 +93,10 @@ int main(){ cout << area(a) + area(b) - intersect(a, t) - intersect(b, t); } ``` +
## Problems + - USACO Bronze - [Fence Painting](http://usaco.org/index.php?page=viewproblem2&cpid=567) - 1D geometry!! @@ -100,5 +107,5 @@ int main(){ - Also rectangles - Other - [CF 587 (Div. 3) C: White Sheet](https://codeforces.com/contest/1216/problem/C) - - See this code (TODO; codeforces is down) for a nice implementation using the Java Rectangle class. + - See this code (TODO; codeforces is down) for a nice implementation using the Java Rectangle class. diff --git a/content/6_Plat/1DRQ.md b/content/6_Plat/1DRQ.md index 48f05a0..aa32f8d 100644 --- a/content/6_Plat/1DRQ.md +++ b/content/6_Plat/1DRQ.md @@ -13,7 +13,7 @@ General range queries for associative operations, including segment tree. ## Static Range Queries -Given a static array $A[1],A[2],\ldots,A[N]$, you want to answer queries in the form $A[l]\ominus A[l+1]\ominus \cdots \ominus A[r]$ in $O(1)$ time each with $O(N\log N)$ time preprocessing, where $\ominus$ denotes any associative operation. In the case when $\ominus$ denotes `min`, preprocessing can be done in $O(1)$ time. +Given a static array $A[1],A[2],\ldots,A[N]$, you want to answer queries in the form $A[l]\ominus A[l+1]\ominus \cdots \ominus A[r]$ in $O(1)$ time each with $O(N\log N)$ time preprocessing, where $\ominus$ denotes any associative operation. In the case when $\ominus$ denotes `min`, preprocessing can be done in $O(N)$ time. ### Tutorial From 0693a604f0dcaf2d541464214af80c0ddd5e2b3b Mon Sep 17 00:00:00 2001 From: caoash Date: Wed, 17 Jun 2020 13:42:42 -0500 Subject: [PATCH 3/4] tested/changed code, all works now --- content/3_Bronze/Rect_Geo.md | 54 +++++++++++++++++++++++++----------- 1 file changed, 38 insertions(+), 16 deletions(-) diff --git a/content/3_Bronze/Rect_Geo.md b/content/3_Bronze/Rect_Geo.md index af67149..29e48ed 100644 --- a/content/3_Bronze/Rect_Geo.md +++ b/content/3_Bronze/Rect_Geo.md @@ -21,15 +21,13 @@ Rectangle newRect = new Rectangle(x, y, width, height); The `Rectangle` class supports numerous useful methods. -``` -firstRect.intersects(secondRect) checks if two rectangles intersect. +`firstRect.intersects(secondRect)` checks if two rectangles intersect. -firstRect.union(secondRect) returns a rectangle representing the union of two rectangles. +`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.contains(x, y)` checks whether the integer point (x,y) exists in firstRect. -firstRect.intersect(secondRect) returns a rectangle representing the intersection of two rectangles. -``` +`firstRect.intersection(secondRect)` returns a rectangle representing the intersection of two rectangles. This class can often lessen the implementation needed in a lot of bronze problems and codeforces problems. @@ -37,38 +35,61 @@ For example, here is a nice implementation of the problem Blocked Billboard (see ```java import java.awt.Rectangle; //needed to use Rectangle class +import java.io.*; +import java.util.*; -public class BlockedBillboard{ +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")); - Rectangle firstRect = new Rectangle(sc.nextInt(), sc.nextInt(), sc.nextInt(), sc.nextInt()); - Rectangle secondRect = new Rectangle(sc.nextInt(), sc.nextInt(), sc.nextInt(), sc.nextInt()); - Rectangle truck = new Rectangle(sc.nextInt(), sc.nextInt(), sc.nextInt(), sc.nextInt()); + 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); + + long firstIntersect = getArea(firstRect.intersection(truck)); + long secondIntersect = getArea(secondRect.intersection(truck)); + pw.println(getArea(firstRect) + getArea(secondRect) - - getArea(firstRect.intersect(truck)) - getArea(secondRect.intersect(truck))); + - firstIntersect - secondIntersect); pw.close(); } public static long getArea(Rectangle r){ - return r.getHeight() * r.getWidth() + if(r.getWidth() <= 0 || r.getHeight() <= 0){ + return 0; + } + return (long)r.getHeight() * (long)r.getWidth(); } } + ``` -(someone test code pls) ## Rectangle Class (C++) 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!). ```cpp +#include +#include +using namespace std; + struct Rect{ int x1, y1, x2, y2; - int area(Rect r){ - 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)); @@ -87,6 +108,7 @@ int main(){ cout << area(a) + area(b) - intersect(a, t) - intersect(b, t); } + ``` ## Problems From 75742f0a692b0dfe01149b5ef1439c1458f3e128 Mon Sep 17 00:00:00 2001 From: caoash Date: Wed, 17 Jun 2020 13:47:10 -0500 Subject: [PATCH 4/4] minor fix --- content/5_Gold/DS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/5_Gold/DS.md b/content/5_Gold/DS.md index af6a8f8..47283c3 100644 --- a/content/5_Gold/DS.md +++ b/content/5_Gold/DS.md @@ -36,7 +36,7 @@ The stack we used is called a "monotonic stack" because we keep popping off the (add more once codeforces comes up) -# Sliding Window (Deque) +# Sliding Window Let's envision a sliding window (or constant size subarray) of size $K$ moving left to right along an array, $a$. For each position of the window, we want to compute some information.