Intro to USACO Strategy

Slides:



Advertisements
Similar presentations
Advanced Programming 15 Feb The “OI” Programming Process Reading the problem statement Thinking Coding + Compiling Testing + Debugging Finalizing.
Advertisements

CS 206 Introduction to Computer Science II 01 / 20 / 2009 Instructor: Michael Eckmann.
Contest format 5 hours, around 8-12 problems One computer running (likely)Linux, plus printer 3 people on one machine No cell phones, calculators, USB.
Inpainting Assigment – Tips and Hints Outline how to design a good test plan selection of dimensions to test along selection of values for each dimension.
Algorithms Analysis Lecture 6 Quicksort. Quick Sort Divide and Conquer.
This title is orange because of Halloween. It is totally not because it’s always orange.
Zhang Hongyi CSCI2100B Data Structures Tutorial 2
CS 206 Introduction to Computer Science II 09 / 09 / 2009 Instructor: Michael Eckmann.
CSE 143 Lecture 4: testing and complexity reading:
Intro to CIT 594
Intro to CIT 594
Introduction to Computers and Programming Lecture 4: Mathematical Operators New York University.
Introduction to Computers and Programming Lecture 15: Arrays Professor: Evan Korth New York University.
Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 4: Enhancing Your Program.
Hash Tables1 Part E Hash Tables  
Chapter 2: Design of Algorithms
CS503: First Lecture, Fall 2008 Michael Barnathan.
Hash Tables1 Part E Hash Tables  
Chapter 11: Limitations of Algorithmic Power
Lecture Notes 8/30/05 Program Design & Intro to Algorithms.
COP 3275 COMPUTER PROGRAMMING USING C Instructor: Diego Rivera-Gutierrez
The break and continue statements. Introduction There are 2 special statements that can affect the execution of loop statements (such as a while-statement)
While Loops and Do Loops. Suppose you wanted to repeat the same code over and over again? System.out.println(“text”); System.out.println(“text”); System.out.println(“text”);
CS1101: Programming Methodology Aaron Tan.
CIS3931 – Intro to JAVA Lecture Note Set 3 19-May-05.
Lecture 2 - Variables, program execution, calculations, print() COMPSCI 101 Principles of Programming.
Polyhedral Optimization Lecture 1 – Part 1 M. Pawan Kumar Slides available online
Jun 16, 2014IAT 2651 Debugging. Dialectical Materialism  Dialectical materialism is a strand of Marxism, synthesizing Hegel's dialectics, which proposes.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2009 Pearson Education, Inc., Upper.
General Programming Introduction to Computing Science and Programming I.
Haskell Chapter 1, Part I. Highly Recommended  Learn you a Haskell for Great Good. Miran Lipovaca.
Moooooo Or: How I learned to stop worrying and love USACO.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Tevfik Bultan Lecture 12: Pointers continued, C strings.
School of Computer Science & Information Technology G6DICP - Lecture 9 Software Development Techniques.
Houyang 3/25/13. USACO March Contest Congrats to Johnny Ho for scoring over 900 points in the Gold Division o 7th place in US Kudos to Jonathan Uesato.
COMP Exception Handling Yi Hong June 10, 2015.
Problem of the Day  Why are manhole covers round?
Lecture 5: Developing Procedural Thinking (How to think like a programmer) B Burlingame 30 Sept 2015.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 5: Software Design & Testing; Revision Session.
Testing. 2 Overview Testing and debugging are important activities in software development. Techniques and tools are introduced. Material borrowed here.
CS1101: Programming Methodology Aaron Tan.
Problem of the Day  Why are manhole covers round?
Please sign in on the sign up sheet MTH Computer Science Club.
C++ Programming Language Lecture 2 Problem Analysis and Solution Representation By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
Program Errors and Debugging Week 10, Thursday Lab.
1Computer Sciences Department. Book: Introduction to Algorithms, by: Thomas H. Cormen Charles E. Leiserson Ronald L. Rivest Clifford Stein Electronic:
Working with arrays (we will use an array of double as example)
CPS120: Introduction to Computer Science Operations Lecture 9.
C++ crash course Class 8 statements, sort, flight times program.
Control Structures II Repetition (Loops). Why Is Repetition Needed? How can you solve the following problem: What is the sum of all the numbers from 1.
Chapter 0 Getting Started. Objectives Understand the basic structure of a C++ program including: – Comments – Preprocessor instructions – Main function.
CS101 Computer Programming I Chapter 4 Extra Examples.
CSC 212 – Data Structures Prof. Matthew Hertz WTC 207D /
The SECOND Meeting Or: How I learned exciting new things in CS Club.
CSC 213 – Large Scale Programming Prof. Matthew Hertz WTC 207D /
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2008 Pearson Education, Inc., Upper.
HKOI Programming HKOI Training Team (Intermediate) Alan, Tam Siu Lung Unu, Tse Chi Yung.
H1-1 University of Washington Computer Programming I Lecture 9: Iteration © 2000 UW CSE.
The SECOND Meeting Or: How I learned exciting new things in CS Club.
CS12230 Introduction to Programming Lecture 6-2 –Errors and Exceptions 1.
Flow of Control: Loops Module 4. Objectives Design a loop Use while, do, and for in a program Use the for-each with enumerations Use assertion checks.
Efficiently Solving Computer Programming Problems Doncho Minkov Telerik Corporation Technical Trainer.
Lecture 3: Developing Procedural Thinking (How to think like a programmer) B Burlingame 16 Feb 2016.
CS Class 04 Topics  Selection statement – IF  Expressions  More practice writing simple C++ programs Announcements  Read pages for next.
Debugging. Design Well A careful design limits the necessary debugging - think “top-down” Write comments as you go, especially invariants –You can test.
Introduction to Computing Science and Programming I
Some Basics for Problem Analysis and Solutions
Presentation transcript:

Intro to USACO Strategy

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++: http://pastebin.com/NP1GuePX has some useful macros Java: http://pastebin.com/tD8z5iMy has some simplifications for i/o Yes, putting 30 #include statements and "throws Exception" everywhere is bad style :P

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

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

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

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.

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

PotW! Bessie is going trick or treating. Input Format Output Format There are N consecutive houses, numbered 1 ... 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

Hint for PotW Bessie is going trick or treating. Example There are N consecutive houses, numbered 1 ... 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 + 3 + -1 + 4) - (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.