【文章內(nèi)容簡介】
thm 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。 verify correctness (use trivial test cases) Try to break the code use special cases for code correctness Optimize progressively only as much as needed, and keep all versions (use hard test cases to figure out actual runtime) Time management strategy and damage control scenarios Have a plan for what to do when various (foreseeable!) things go wrong。 imagine problems you might have and figure out how you want to react. The central question is: When do you spend more time debugging a program, and when do you cut your losses and move on?. Consider these issues: How long have you spent debugging it already? What type of bug do you seem to have? Is your algorithm wrong? Do you data structures need to be changed? Do you have any clue about what39。s going wrong? A short amount (20 mins) of debugging is better than switching to anything else。 but you might be able to solve another from scratch in 45 mins. When do you go back to a problem you39。ve abandoned previously? When do you spend more time optimizing a program, and when do you switch? Consider from here out forget prior effort, focus on the future: how can you get the most points in the next hour with what you have? Have a checklist to use before turning in your solutions: Code freeze five minutes before end of contest? Turn asserts off. Turn off debugging output. Turn on all optimizations. Make sure input and output are to correct filenames. Make sure the input and output formats are correct. Repile and test once more. Copy files to correct locations (floppy?) with correct names. Tips amp。 Tricks Brute force it when you can KISS: Simple is smart! Hint: focus on limits (specified in problem statement) Waste memory when it makes your life easier (if you can get away with it) Don39。t delete your extra debugging output, ment it out Optimize progressively, and only as much as needed Keep all working versions! Code to debug: whitespace is good, use meaningful variable names, don39。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。 if you have to, put tolerances in everywhere (never test equality) Comments on ments: Not long prose, just brief notes Explain highlevel functionality: ++i。 /* increase the value of i by