Presentation is loading. Please wait.

Presentation is loading. Please wait.

Intro to USACO Strategy U-SA-CO. USACO Basics If "prog" is the name of the problem: Read from "prog.in" and write to "prog.out" o Use freopen if you use.

Similar presentations


Presentation on theme: "Intro to USACO Strategy U-SA-CO. USACO Basics If "prog" is the name of the problem: Read from "prog.in" and write to "prog.out" o Use freopen if you use."— Presentation transcript:

1 Intro to USACO Strategy U-SA-CO

2 USACO Basics If "prog" is the name of the problem: Read from "prog.in" and write to "prog.out" o Use freopen if you use C/C++ o Use BufferedReader if you use Java Make sure class and source names match o E.g. "Main.java" and "public class Main {" Templates: o C++: has some useful macros o Java: has some simplifications for i/o Yes, putting 30 #include statements and "throws Exception" everywhere is bad style :P

3 Preparing for the USACO train.usaco.org o Organized in chapters and sections o Has explanations for necessary algorithms o The problems get hard quickly. You do not need to know all six chapters past USACO problems o Google them! Miscellaneous online websites o codeforces.com Highly recommended Want to make gold? Try doing 300 problems :D o poj.org Our PotWs o Free lectures, yo Cows <3

4 USACO Tips Read the problem CAREFULLY o Check boundaries Running time is VERY important o ~10 8 operations per sec (conservative estimate) Do not start coding until you know how to solve the problem o Of course, if you have no idea or are running out of time, brute force Code! Use Google wisely Test your program if you have time o Check small cases by hand o Make a random test case generator

5 Random Coding Tips Watch out for off-by-one errors o Make arrays slightly bigger than needed Watch out for overflow o int = ~10 9 maximum o long = ~10 18 maximum Debugging o Avoid it. o Use print statements o "Rubber duck debugging" Variable names o l is the worst variable name ever Use pseudocode/scratch paper Use shortcuts Speak to the duck

6 Things to Avoid Spending too much time on one problem o You can always come back o You need near perfect to be promoted to higher divisions Coding a solution only to discover your method doesn't work on the sample case Premature optimization Being sketchy Using long variable names o Typing takes longer than you think Excessive commenting o Just a few words for yourself Multitasking on your computer :'( Avoid this.

7 What happens after my timer is over? Congrats on your hard work Results announced the following week o ~Thursday Rankings can be checked on tjhsst's website o ~Following weekend...? Go practice more

8 PotW! Bessie is going trick or treating. o There are N consecutive houses, numbered 1... N. o The i_th house gives a_i pieces of candy. o Bessie must visit a nonempty consecutive sequence of houses. o Find the maximum amount of candy she can get. Input Format o Line 1: A single integer: N o Line 2: N space separated integers: a_1... a_N Output Format o Line 1: The maximum amount of candy she can get. Constraints o 15 Points: N < 1000, |a_i| < 1000 o 25 Points: N < 100,000, |a_i| < 10^9 o 35 Points: Maximize the amount of candy mod M. Line 1: Two space separated integers, N, M N < 100,000, 0 < a_i < M < 10^9

9 Hint for PotW Bessie is going trick or treating. o There are N consecutive houses, numbered 1... N. o The i_th house gives a_i pieces of candy. o Bessie must visit a nonempty consecutive sequence of houses. o Find the maximum amount of candy she can get. Example o N = 6, a = {1, -2, 3, -1, 4, -3} o The best sum is 3 + (-1) + 4 = 6 o Notice that this is a difference of prefix-sums ( ) - (1 + -2) = 5 - (-1) = 6 How do you maximize this? o X - Y is maximized when Y is minimized. o Keep track of what sum to subtract -- you always want to subtract the most negative one.


Download ppt "Intro to USACO Strategy U-SA-CO. USACO Basics If "prog" is the name of the problem: Read from "prog.in" and write to "prog.out" o Use freopen if you use."

Similar presentations


Ads by Google