Sunday, March 19, 2017

Algorithm lists. You have to know

Even though we are the same codeforces color >.<, i still have valuable advice to provide. My red friends on codeforces have stuck to this method. I have used this also to make the gold division in USACO.
Step 1: Learn and Practice Algorithms
Start from some simple and basic algorithms and practice them thoroughly:
-Sorting
-Scanline (Sweep line)
-traversals
-binary search
-MST/shortest paths
-DP
-Simple data structures:
-dsu, sets, map, heap, queue, stack, deque
Then proceed on to more devious and complex algorithms:
-Greedy
-DAGs, SSCs, Bi-connected compnents
-DP + caching previous results
-compression
-Convex Hull
-Complex Data structures:
-segment trees, linked list, BIT, Trie, Splay, Suffix Trees
-KMP/String hashing/string algorithms
-mincut/maxflow/maxmatching
Step 2: Look at Problems, Know what type of problem it is
I suggest you turn off the tags for unsolved problems so you can try to decide what type of problem you are solving.
At this step, you should try to: -know how to turn this problem into something familiar, into a graph? How will you handle updates? queries?
-know how to handle constraints of the problem. Do you need to add more states?
-Make observations about the problem, if the problem gives huge constraints like 10^6 and then suddenly gives a small constraint of 10, you should take advantage of that. Of course there are many different observations that you can make to help you solve problems.
Note at this step you do not need to necessarily code up the solution, you just need to form a clear approach in your mind.
Step 3: Implementation
Here is when you need to not only recognize the type of problem, but also know how to implement it. This is what I am bad at. My suggestions are:
  1. order the codeforces problemset by solved and burn through the first 4~5 pages. I have finished the first 3 already.
  2. Practice problems that require more than a direct approach. These problems can combine algorithms like dp with complex data structures, here is an example: http://www.usaco.org/index.php?page=viewproblem2&cpid=365
Other Tips:
When doing codeforces problems, if you get a wrong answer during practice, try not to scroll through the test data to see what you got wrong. Try to test your code again and see if you can fix your bug, this really helps during a contest. This is how I can recover from hacks. Do not only do codeforces (although I think codeforces's problemset is the best), do other sites that have even more archive of problems like POJ, SPOJ, USACO / USACO Training Gateway, etc.

Hope this helps! Trust me, this is how I got into USACO Gold! Just follow this list!

Resource Link: http://codeforces.com/blog/entry/2332#comment-176240

No comments:

Post a Comment