This post assumes that you possess a foundational understanding of algorithms and are acquainted with the Java programming language.
What is USACO?
What is USACO, and why should you utilize it to embark on your competitive programming journey?
The USACO (United States of America Computing Olympiad) is a prestigious programming contest for high school students in the United States. Top scorers in the USACO US Open Competition are chosen to represent the National U.S Programming Team, which competes in the IOI (International Olympiad in Informatics).
The USACO organization has developed an online training platform for students to hone their programming skills through an array of carefully crafted problems, which can be completed at their own pace. These training problems are so well-constructed that the majority of their users are members of other countries’ national IOI teams (e.g., China, Russia, India, etc.).
So, how do you begin utilizing this invaluable resource? Simply visit http://train.usaco.com/usacogate and sign up for a free account.
Bear in mind that the problems are designed to be challenging. Attempt just one problem a day, and seek online assistance if you find yourself stuck (e.g., Stack Overflow). If you know someone at a similar programming level, consider forming an online group with them to monitor progress and seek help when necessary.
After creating an account, sign in and dive into the texts and problems!
Tackling Your First USACO Problems
The website presents a list of links, categorized as either TEXT or PROB. TEXTs provide guidance for the upcoming problems, while PROBs are the actual programming challenges. The first two TEXTs serve as an introduction to the website’s format.
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.
If you’re using Eclipse, open Windows Explorer (the application used for navigating files/folders) and locate your Eclipse Workspace (search online if you’re unsure how). Find your project (a folder named “USACO”), right-click it, and create a shortcut. Drag the shortcut onto your desktop for easy access to your project folder!
Double-click on USACO again and right-click within the window that appears. Click “Create New File” and generate “file.in” and “file.out”. You can then close the folder and return to Eclipse. Two new files named “file.in” and “file.out” should be visible in the workspace on the left. If they’re named “file.in.txt” or similar, right-click the file and refactor/rename it to “file.in” (and do the same for “file.out”).
If you’re using Eclipse or another IDE with a console for input and output, remember that USACO does NOT use the console. Instead, your program should rely on input/output FILES. Your program needs to open an input file containing text or numbers, perform the requested tasks, and then paste the results into an output file.
The lines of code above “Get line, break into tokens” handle input/output, while the lines of code above “out.close()” constitute the program’s core. If you have trouble understanding the input/output section, 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.