Setup Guide

User Manual:

Open the PDF directly: View PDF PDF.
Page Count: 3

USACO Setup Guide
Sebastian Jeon, Sameer Pai
September 12, 2018
”don’t be bad” - Ancient Proverb
§1What is USACO?
USACO stands for the USA Computing Olympiad. It aims to test students’ algorithmic
programming skills. Throughout the year, there are four contests (December, January,
February, and the US Open). In each contest, you have 4-5 hours to solve 3 programming
questions. There are four divisions: Bronze, Silver, Gold, and Platinum. If you do well
on one division, you are permanently promoted to the next division (i.e. you can’t get
demoted, ever). More information is provided on the USACO Site (usaco.org).
§2Getting Started
You’ll need to make two accounts: one on
train.usaco.org
, and one on
usaco.org
.
These accounts are not linked at all. The first link contains many training problems,
and the second is where you’ll be actually taking contests. More detailed resources are
available at http://usaco.org/index.php?page=resources.
§2.1 Before You Start
First, learn a programming language. These handouts will be written in C++, and we
strongly recommend learning this language. Java is usable for the most part, but it is
heavily recommended that you avoid Python.
One good site to learn C++ is
learncpp.com
. You can skip all of the object-oriented
stuff, and most of the pointer stuff. Read chapters 1-7 there, and then 16-18. You
shouldn’t try to do the USACO training pages before you are adequately familiar of your
language of choice.
§2.2 Problem Format
Now you know a language (hopefully), and you’re ready to solve problems. All USACO
problems have the exact same input and output formats. Specifically, each problem has
a specific task name (which is not the problem name). When you submit a program, it is
run by the USACO grader (a program that judges your code to see if it works). Your
program should take input from the file ”taskname.in”. Using this input, your program
should do what the problem wants you to do (i.e. get the answer!). Then, it should
output whatever answer the problem wants to the file ”taskname.out”. There are 10(ish)
test cases for every problem, meaning that the grader gives your program 10 different
inputs.
1
Sebastian Jeon, Sameer Pai (September 12, 2018) USACO Setup Guide
§2.3 The First Problem
If you have done everything correctly, you should have made it to the first problem
in the training pages called ”Your Ride Is Here”. As this problem is intended to be
an introduction to competitive programming, we present the solution code along with
analysis on the next page. More experienced programmers are encouraged to solve this
by themselves before reading the solution.
1/
2NAME: i n s e r t your username
3TASK: r i d e
4LANG: C++11
5/
6// header
7
8#include <b i t s / s td c++.h>// b a s i c a l l y a l l o f the packages
9usin g namespace std ;
10
11 i n t s c o r e (string s)
12 {
13 i n t prod = 1 ;
14 f o r (char arg :s){
15 prod = ( arg A ’ + 1) ;
16 }
17 r e t u r n prod % 4 7 ;
18 }
19 i n t main ( )
20 {
21 i f s t r e a m f i n ( r i d e . i n ” ) ;
22 o fs t re a m f o u t ( r i d e . out ” ) ; // open inp ut f i l e s
23
24 s t r i n g comet ,group ;
25 fin >> comet >> group ;
26 i f (s c o r e (comet) == score(group) )
27 fout << GO\n;// t ermi n ate output with a new l i n e
28 e l s e
29 fout << STAY\n;
30 }
This code has three main parts: getting the input, getting the answer, and printing the
answer. Hopefully you know how file input works, so we won’t go over that. The score
is calculated using the function
score()
, by splitting up the string into its individual
characters and multiplying each of them together. Note that in ASCII (the encoding
that C++ uses for characters), subtracting a letter from the value ’A’ gives the value of
that letter (i.e. ’A’ - ’A’ = 0, etc.). On
train.usaco.org
, you have to have a header (i.e.
comments at the top of your code) that has your username (mine is sameerp2), the task
name, and the language. You should be able to copy-paste this code into a file on your
computer (change the name at the top!), and submit it. Congratulations! You solved a
problem!
2
Sebastian Jeon, Sameer Pai (September 12, 2018) USACO Setup Guide
§3What Now?
Now that you know the technical details about how to submit a problem, you can start
learning actual algorithms.
3

Navigation menu