Download presentation

Presentation is loading. Please wait.

1
**Intro to USACO Strategy**

2
**USACO Basics If "prog" is the name of the problem:**

Read from "prog.in" and write to "prog.out" Use freopen if you use C/C++ Use BufferedReader if you use Java Make sure class and source names match E.g. "Main.java" and "public class Main {" Templates: C++: has some useful macros 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 Organized in chapters and sections Has explanations for necessary algorithms The problems get hard quickly. You do not need to know all six chapters past USACO problems Google them! Miscellaneous online websites codeforces.com Highly recommended Want to make gold? Try doing 300 problems :D poj.org Our PotWs Free lectures, yo Cows <3

4
**USACO Tips Read the problem CAREFULLY Running time is VERY important**

Check boundaries Running time is VERY important ~108 operations per sec (conservative estimate) Do not start coding until you know how to solve the problem 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 Check small cases by hand Make a random test case generator

5
**Random Coding Tips Watch out for off-by-one errors**

Make arrays slightly bigger than needed Watch out for overflow int = ~109 maximum long = ~1018 maximum Debugging Avoid it. Use print statements "Rubber duck debugging" Variable names 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**

You can always come back 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 Typing takes longer than you think Excessive commenting 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 ~Thursday Rankings can be checked on tjhsst's website ~Following weekend...? Go practice more

8
**PotW! Bessie is going trick or treating. Input Format Output Format**

There are N consecutive houses, numbered N. The i_th house gives a_i pieces of candy. Bessie must visit a nonempty consecutive sequence of houses. Find the maximum amount of candy she can get. Input Format Line 1: A single integer: N Line 2: N space separated integers: a_1 ... a_N Output Format Line 1: The maximum amount of candy she can get. Constraints 15 Points: N < 1000, |a_i| < 1000 25 Points: N < 100,000, |a_i| < 10^9 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. Example**

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

Similar presentations

OK

Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 5: Software Design & Testing; Revision Session.

Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 5: Software Design & Testing; Revision Session.

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google

Ppt on eisenmenger syndrome image Ppt on credit default swaps and the financial crisis Ppt on energy giving food Ppt on different types of forests in india Ppt on ip address classes a b Download ppt on conservation of resources Ppt on ms excel tutorial Ppt on mass production Ppt on needle stick injury policy Ppt on media and communication