【正文】
ten use prime numbers many times it is practical to generate a long list of primes for use elsewhere in a program. Deposition (The Hardest Thing At Programming Contests) While there are fewer than 20 basic algorithms used in contest problems, the challenge of bination problems that require a bination of two algorithms for solution is daunting. Try to separate the cues from different parts of the problem so that you can bine one algorithm with a loop or with another algorithm to solve different parts of the problem independently. Note that sometimes you can use the same algorithm twice on different (independent!) parts of your data to significantly improve your running time. Symmetries Many problems have symmetries (., distance between a pair of points is often the same either way you traverse the points). Symmetries can be 2way, 4way, 8way, and more. Try to exploit symmetries to reduce execution time. For instance, with 4way symmetry, you solve only one fourth of the problem and then write down the four solutions that share symmetry with the single answer (look out for selfsymmetric solutions which should only be output once or twice, of course). Forward vs. Backward Surprisingly, many contest problems work far better when solved backwards than when using a frontal attack. Be on the lookout for processing data in reverse order or building an attack that looks at the data in some order or fashion other than the obvious. Simplification Some problems can be rephrased into a somewhat different problem such that if you solve the new problem, you either already have or can easily find the solution to the original one。 use this to rewrite and improve your game plan! Complexity Basics and order notation The fundamental basis of plexity analysis revolves around the notion of ``big oh39。t reuse variables, stepwise refinement, COMMENT BEFORE CODE. Avoid pointers if you can Avoid dynamic memory like the plague: statically allocate everything. Try not to use floating point。 but you might be able to solve another from scratch in 45 mins. When do you go back to a problem you39。 time plexity, and plug in actual expected and worst case numbers) Try to break the algorithm use special (degenerate?) test cases Order the problems: shortest job first, in terms of your effort (shortest to longest: done it before, easy, unfamiliar, hard) Coding a problem For each, one at a time: Finalize algorithm Create test data for tricky cases Write data structures Code the input routine and test it (write extra output routines to show data?) Code the output routine and test it Stepwise refinement: write ments outlining the program logic Fill in code and debug one section at a time Get it working amp。 Receipted from Translated