The Hitchhiker's Guide to Competitive Programming
Hi there fellow novice! You are about to embarked on a journey of creative problem-solving, of late-nights and frustrating prospects - you are landing on the planetary divide of competitive programming.
So what is it? Well, in laymen's terms, it's using computers to solve problems for you. It's like math for lazy people (or lazy people, period). And obviously, we compete (hence, the 'competitive' part of the subject). It's a chance to dive deep into the thinking part of computer science and learn the what, how, and why. And more importantly, it's one-hundred percent hands-on (so yes, you get to fail in realtime).
In short, it's like AP Computer Science on steroids (but more fun with the added bonus of free pizza on Saturday contests).
As you work through this book, you're going to get stuck. Like, really stuck. And you'll want to give-up and never open up an IDE ever again. You'll remove this from your bookmarks, and say yada yada programming's too hard. Fine, I get it. It's not everyone's cup of tea. But I'm a firm believer that you should always try, and that you should at least go to one contest before you call it quits.
I suggest you maintain this approach as you program, and what to do when you get stuck:
- Read the damn problem. Sometimes you miss test cases, sometimes it's just formatting and the judge's are really picky and want you to print the solution out in a super fancy way, or sometimes, you realize that your solution isn't what the problem was asking for e.g. printing out all odd numbers when the problem asked for even numbers.
- Work it out on paper first. If the problem is not stupidly simple or not similar to a problem you have solved before, work it out on paper first. Write pseudocode and try executing some simple test cases by hand. This lets you catch flaws in the algorithm before you write any real code, so you will be certain that if your code doesn't work, it will be due to something like a typo and not a fundamental defect in the algorithm.
- Search. Google exists for a reason. Every programmer, and I mean every programmer googles. It's okay to use websites like StackOverflow or forums, as long as you're not looking at the solution. I repeat, do not just google the answer. It's like math homework. Do you just type in 'what is x in the equation 5x + 3 = 2' - no, you look at examples, you find similar problems and similar tools that'll help you in learning and solving the problem.
- Ask. There's always someone after school, and more importantly, the computer lab is always open. We're available and you're free to ask for help. Just don't expect us to code it for you. But even the authors of this book are excited about teaching you - so don't be afraid, and don't be shy.
- Take a break. If you just can't take it anymore, and the all of the above don't work out. Then take a break, as long as you need to. And think about the problem in the back of your mind in a relaxed and casual manner. You'll be surprised about what you can come up with at 2 am in the morning coding.
Good luck!