This post assumes that you already have a basic grasp of algorithms, and that you are proficient in the Java programming language.
What is USACO?
What is USACO, and why should you use it to start to learn how to program competitively?
The USACO (United States of America Computing Olympiad) is a programming competition for high schoolers in the United States. The top scorers in the USACO US Open Competition are selected to be part of the National U.S Programming Team, who will then compete in the IOI (International Olympiad in Informatics).
The USACO.comanization has created an online training website for students to develop their programming skills in a variety of different problems, to be completed at the students’ own pace. The training problems are so well made, that the majority of the users of the training pages are from the national IOI teams of other countries (i.e China, Russia, India, etc.)
So how do you get started using this resource? Just visit http://train.usaco.com/usacogate, and sign up for a free account.
Keep in mind that the problems are meant to be difficult. Try tackling just 1 problem a day, and relying on online help if you get stuck (Stack Overflow). If you know anyone around your programming level, I’d recommend setting up an online group with them to keep track of your progress and ask for help if needed.
Now that you’ve got an account, sign in and start reading the texts/ doing the problems!
Doing the first few USACO problems
The site is represented as a list of links, each designated as either a TEXT, or a PROB. TEXTs explain what you should for the upcoming problems, and PROBs are the actual programming problems. The first two TEXTs are an introduction to the format of the website.
The second TEXT has snippets of code for each programming language. Scroll down to the JAVA one and copy that. Then open up the programming IDE of your choice (ex: Eclipse), and create a new Java Project named USACO.
Then create a new class with the name of the PROB (in this case, it would just be “test”). Paste the “test” code into it, and save (ctrl+s).
Now, open up Windows Explorer (the program that you use to navigate files/folders), and search for your Eclipse Workspace (again, if you don’t know how, look it up). Once there, look for your project (it should be a folder named ‘USACO’), right click it, and create a shortcut. Drag that shortcut onto your desktop. Now you have easy access to your project folder!
Double click on USACO again, and right click the window when it comes up. Click on create new file, and create “file.in” and “file.out”. You can then close the folder and go back to eclipse. You should see two new files named “file.in” and “file.out” in the workspace to the left. If it is named “file.in.txt” or something similar, right click the file, and refactor/rename it to file.in. Same thing with file.out.
If you use Eclipse or any other IDE that has a console for input and output, note that for USACO, you do NOT use the console. Instead, you rely on two input/output FILES. Your program needs to open up an input file, which has a bunch of text or numbers in it. The program then does whatever you ask it to, and then pastes it into the output file.
Lines of code above “Get line, break into tokens” are the input/output part of the program. Lines of code above out.close() are the actual meat of the program. If you have trouble understanding the input/output part of it, try looking up the code online.
Put some numbers in the test.in file, run the program, and then check the test.out!
Once you’ve finished playing with the test program, go back to the USACO Text, and upload the file.
Once it says your program has passed, you can go to your first PROB, RIDE. Create a new class named RIDE, and set up your input output. You can use the same files, “test.in” and “test.out”, since your RIDE class is in the same project as the files.
However, once you submit the official program, you will need to change the code of the program to say “ride.in” and ride.out” for the input and output files, because those are the names of the files that USACO uses on their end.
Note that for the RIDE program, the problem is asking for input from multiple lines, rather than the first program, which asked for input from a single line.
An aside to future frustrated students
Everyone struggled through the same infuriatingly simple bugs that you’re going to be encountering in the next few weeks. Embrace the challenge, feel dumb, and push through to understand whatever you’re stuck on.