1 / 9

Moooooo

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 (

nassor
Download Presentation

Moooooo

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. 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));intnumCows = Integer.parseInt(in.readLine());intninjaCow = numCows;         for (inti = 1; i < numCows; i++)ninjaCow = ninjaCow ^ i ^ Integer.parseInt( in.readLine()); System.out.println(ninjaCow);    }}

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

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

  5. Details • Example: if the name of the task is "cowmilk" • I/O • Scan from a file - "cowmilk.in" • 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

  6. Java I/O import java.io.*; import java.util.*; BufferedReaderbr = 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 <fstream> using namespace std; fstreami("cowmilk.in"),o("cowmilk.out"); (yes, really)

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

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

  9. 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"): " abcddcba\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.

More Related