Moooooo Or: How I learned to stop worrying and love USACO.

Slides:



Advertisements
Similar presentations
Overview of programming in C C is a fast, efficient, flexible programming language Paradigm: C is procedural (like Fortran, Pascal), not object oriented.
Advertisements

LYNBROOK COMPUTER SCIENCE CLUB MONDAY, OCTOBER 26, 2009 POWERPOINT CREATED BY: RITIK MALHOTRA PRESENTATION BY: KARTHIK VISWANATHAN Intro to USACO.
This title is orange because of Halloween. It is totally not because it’s always orange.
Welcome to CodeWarmers!
Intro to USACO Strategy
Algorithms and Problem Solving
Text File I/O. Text Files and Binary Files Files that are designed to be read by human beings, and that can be read or written with an editor are called.
Unit 201 FILE IO Types of files Opening a text file for reading Reading from a text file Opening a text file for writing/appending Writing/appending to.
1 LECTURE#7: Console Input Overview l Introduction to Wrapper classes. l Introduction to Exceptions (Java run-time errors). l Console input using the BufferedReader.
Looping Yong Choi School of Business CSU, Bakersfield.
Unit 171 Algorithms and Problem Solving - II Algorithm Efficiency Primality Testing Improved Primality Testing Sieve of Eratosthenes Primality Testing.
1 Introduction to Console Input  Primitive Type Wrapper Classes  Converting Strings to Numbers  System.in Stream  Wrapping System.in in a Buffered.
Strings and File I/O. Strings Java String objects are immutable Common methods include: –boolean equalsIgnoreCase(String str) –String toLowerCase() –String.
Chapter 3b Standard Input and Output Sample Development.
COMPSCI 125 Spring 2005 ©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 3: IO *Standard Output *Formatting Decimal.
Programming Contest problems Dr. Jeyakesavan Veerasamy CS faculty, The University of Texas at Dallas Website:
Week 2 - Friday.  What did we talk about last time?  Data representation  Binary numbers  Types  int  boolean  double  char  String.
Streams and File I/O Chapter 14. I/O Overview I/O = Input/Output In this context it is input to and output from programs Input can be from keyboard or.
CIS 068 JAVA I/O: Streams and Files. CIS 068 I/O Usual Purpose: storing data to ‘nonvolatile‘ devices, e.g. harddisk Classes provided by package java.io.
Week 14 - Monday.  What did we talk about last time?  Image manipulation  Inheritance.
Exceptions 1. Your computer takes exception Exceptions are errors in the logic of a program (run-time errors). Examples: Exception in thread “main” java.io.FileNotFoundException:
Very Brief Introduction to Java I/O with Buffered Reader and Buffered Writer.
CSI 1390: Introduction to Computers TA: Tapu Kumar Ghose Office: STE 5014
1 Java Console I/O Introduction. 2 Java I/O You may have noticed that all the I/O that we have done has been output The reasons –Java I/O is based on.
Week 1 - Friday.  What did we talk about last time?  Our first Java program.
Computer Science Club It is easier to change the specification to fit the program than vice versa.
Please sign in on the sign up sheet MTH Computer Science Club.
CS 206 Introduction to Computer Science II 09 / 10 / 2009 Instructor: Michael Eckmann.
20 Oct - Overview Homework #1 Group-Id rule Notes on Java text file input/output –Scanner class –Printf (like C)
1 BUILDING JAVA PROGRAMS CHAPTER 6 FILE PROCESSING.
CIS 260: App Dev I. 2 Programs and Programming n Program  A sequence of steps designed to accomplish a task n Program design  A detailed _____ for implementing.
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
CSci 111 – computer Science I Fall 2014 Cynthia Zickos WRITING A SIMPLE PROGRAM IN JAVA.
Java basics. Task  Display the supposed forecast I think there is a world market for maybe five computers. Thomas Watson, IBM, 1943.
CMSC 202 Text File I/O. Aug 8, Text Files and Binary Files Files that are designed to be read by human beings, and that can be read or written with.
5-Dec-15 Sequential Files and Streams. 2 File Handling. File Concept.
The SECOND Meeting Or: How I learned exciting new things in CS Club.
Introduction Chapter 1 8/31 & 9/1 Imagine! Java: Programming Concepts in Context by Frank M. Carrano, (c) Pearson Education - Prentice Hall, 2010.
Week 14 - Monday.  What did we talk about last time?  Inheritance.
Not a Math Honor Society meeting. Or: How I learned to do math again, this time with cows.
CSI 3125, Preliminaries, page 1 Java I/O. CSI 3125, Preliminaries, page 2 Java I/O Java I/O (Input and Output) is used to process the input and produce.
BHCSI Programming Contests. Three contests Mock Contest #1  Friday, July 16 th  2:15 – 4:45pm UCF High School Online Contest  Thursday, July 22 nd.
I/O Basics 26 January Aside from print( ) and println( ), none of the I/O methods have been used significantly. The reason is simple: most real.
The SECOND Meeting Or: How I learned exciting new things in CS Club.
CSCI 1100/1202 January 23, Class Methods Some methods can be invoked through the class name, instead of through an object of the class These methods.
Introduction to C++.  Computers: CPU, Memory & Input / Output (IO)  Program: Sequence of instructions for the computer.  Operating system: Program.
Files Review For output to a file: –FileOutputStream variable initialized to filename (String) and append/not append (boolean) –PrintWriter variable initialized.
Strings and File I/O. Strings Java String objects are immutable Common methods include: –boolean equalsIgnoreCase(String str) –String toLowerCase() –String.
Programming Principles Operators and Expressions.
Introduction to programming in java
Reading from a file and Writing to a file
Strings and File I/O.
File Input and Output TOPICS File Input Exception Handling File Output.
CS1101: Programming Methodology Recitation 7 – Exceptions
Interactive Standard Input/output
COMPUTER 2430 Object Oriented Programming and Data Structures I
CHAPTER 5 JAVA FILE INPUT/OUTPUT
Lecture Note Set 1 Thursday 12-May-05
Week 14 - Wednesday CS 121.
I/O Basics.
Computer Programming Methodology File Input
File Input and Output TOPICS File Input Exception Handling File Output.
Week 6 Discussion Word Cloud.
Unit 6 Working with files. Unit 6 Working with files.
MSIS 655 Advanced Business Applications Programming
Java for IOI.
CSC1401 Input and Output (with Files)
មជ្ឈមណ្ឌលកូរ៉េ សហ្វវែរ អេច អ ឌី
Exception Handling Contents
EECE.3220 Data Structures Instructor: Dr. Michael Geiger Spring 2019
Presentation transcript:

Moooooo Or: How I learned to stop worrying and love USACO

Or: How I learned the solution to last week’s PotW 20 point solution: import java.io.*; public class PotW1 { public static void main(String[] Args) throws IOException { BufferedReader in = new BufferedReader( new InputStreamReader(System.in)); int numCows = Integer.parseInt(in.readLine()); int ninjaCow = numCows; for (int i = 1; i < numCows; i++) ninjaCow = ninjaCow ^ i ^ Integer.parseInt( in.readLine()); System.out.println(ninjaCow); } }

General Info Main US high school programming contest o Sign up online - o Training pages - o Similar to USA(J)MO 6 contests each year Three divisions - Bronze, Silver, Gold o Silver and Gold are by invitation only o Higher divisions are more difficult Exact schedule TBD o Qualification round probably at end of October o The format for qualification round is different Again, TBD, so look for updates

Format problems hours (that's right: hours per problem!) Problems are algorithmic o Occasionally need some math Given a problem statement o And sample input / output o Write a program! o Subject to time and memory constraints o Multiple submissions allowed Last submission by end of contest will be tested o This test data is unknown to you o Get points for each test case you pass

Details Example: if the name of the task is "cowmilk" I/O o Scan from a file - "cowmilk.in" o Write to another file - "cowmilk.out" Header (place this comment at the top of code): /* ID: username TASK: cowmilk LANG: JAVA ( or C++ ) */ Read the rules for more details

Java I/O import java.io.*; import java.util.*; BufferedReader br = new BufferedReader(new FileReader("cowmilk.in")); Scanner s = new Scanner(new File("cowmilk.in")); PrintWriter o = new PrintWriter(new BufferedWriter(new FileWriter("cowmilk.out"))); In C++: #include using namespace std; fstream i("cowmilk.in"),o("cowmilk.out"); (yes, really)

Time Flies! Time limit is very important o Depends on the efficiency of your algorithm o e.g. how quickly can you add up the numbers from 1 - N? one step - N*(N+1)/2 o Java can do about 200,000,000 operations per second (grader scales to 700MHz) dividing doubles, calling methods, casting classes, etc. o Estimate how many operations your solution will do o C/C++ and Pascal are often faster than Java Memory is not that important Do not waste time making premature optimizations in speed o Often okay to sacrifice a little efficiency for ease of coding o Only make optimizations that can increase speed by an order of magnitude

STRATEGY Practice o Preferably before the contest Read each problem: o Read the problem again o Read the time / memory constraints o Read the sample input / output Think logically. Notice small details. Be flexible and creative. So you think you have a solution? o Make sure you can actually code your solution o Check if your solution works by hand before coding o Look for corner cases o Test your solution on your own data Feel free to skip problems - they are never in order of difficulty o Partial solutions are also good

PotW – The White Textfile In a fit of schizophrenic hatred for Microsoft, you decide to go "creep" around in Windows Explorer, normalizing all of your text files into a less "revolting" format. (sorry, no cows this time) Your goal is to take a text file, which is composed of words delimited by any whitespace (' ', '\n', '\t', '\r'), and convert it into a text file that is composed of words delimited by '\n' only. We will be using USACO conventions for I/O. Sample input ( "whitetext.in" ): " abcd dcba\nuvw\r\nz \t" Sample output ( "whitetext.out" ): "abcd\ndcba\nuvw\nz" - no ending or starting newlines (without the quotations, of course) You will receive 8 pts for each solution you submit (up to 16 total) The two solutions must be radically different.