6 May 2011

Step by Step..ACM ICPC

- Chua Hock-Chuan (ehchua@ntu.edu.sg)
Step 1 – Try PKU Online Judge

  1. Register with PKU online judge @ http://acm.pku.edu.cn/JudgeOnline/.
  2. Read the FAQ to understand to submission rules – IMPORTANT!
  3. Read the FAQ AGAIN.
  4. The programming rules for ICPC are:Java Language
    • Input comes form System.in and output goes to System.out (no File IO allowed).
    • The source file must contain a class called Main with the entry-method main:
      public static void main(String[] args) { ... }.

    C++ Language

    • Input comes form std:cin and output goes to std:cout (no File IO allowed).
    • The source file must contain the entry-function int main() { ... }.
  5. Try the first problem “1000 (A+B)” with the solution provided in FAQ. The purpose of this problem is to let you understand the above programming rules. In your submission, make sure you specify the language used (“Java”, “G++” for GNU C++ compiler, or “C++” for VC6 compiler).For Java programmers
    You should program at JDK 1.5 or above. Use Scanner, in.nextInt(), in.nextDouble(), in.next() for inputting int, double, and String, and C-like System.out.printf("formatString", args...) for output.
    JDK 1.5 Program Template for ICPC Online Judge

    import java.util.Scanner;
    public class Main {   // save as Main.java
       public static void main(String[] args) {
          Scanner in = new Scanner(System.in);
          int    i = in.nextInt();    // read int
          double d = in.nextDouble(); // read double
          String s = in.next();       // read String
          // There is no nextChar(), use next() and charAt()
          char c = s.charAt(2);
          // Read whole line (or rest of the line past '\n')
          String line = in.nextLine();
          System.out.printf("%4d, %6.2f, %s, %c\n", i, d, s, c);
          // Use %f for double (not %lf)
          // Don't forget to print the '\n'
  6. Try another few (extremely) simple problems (you can look at the percentages to estimate the difficulty of the problems)
    • Read the programming rules AGAIN before trying these problems.
    • You input and output must strictly follow the description given. You need not and CANNOT print input prompting message such as “Please enter a number” (because nobody is sitting at the online judging system to read these prompts).
    • Do “1004 (Financial Management)” – Simply averaging 12 numbers
      Hints: To test this program, you have two options: (a) key in the 12 numbers slowly, or (b) save the 12 numbers in a file, says “in.txt“, start a Command shell (“cmd“), and use the “pipe” operator “<” to re-direct the input from the file “in.txt” to the stdin as follows:
      For Java Programmers
      Assume that the source file is called Main.java

      > javac Main.java
      > java Main < in.txt

      For C++ programmers
      Assume that the source file is called test.cpp

      > g++ -o test.exe test.cpp
      > test < in.txt
    • “1003 (Hangover)” – Compute the sum of a harmonic series and compare…
    • “1005 (I think I need a house boat)” – Compute the area of a semi-circle and compare…

Step 2 – Try UVA Online Judge: This site is meant for C/C++ programmers. Java programmers can forget about this site (as there is no support for JDK 1.5). For C programs, you cannot use // comments.

  1. Register with UVA online judge @ http://online-judge.uva.es/problemset/.
  2. Read the HOWTOs, especially on how to submit solution.
  3. Try the first problem Volume 1 Problem 100 (3n+1) with the solution provided in HOWTOs.

The above steps are meant for you to familiarize with the contest process. Here come the “serious” training…

Step 3 – Try USACO Training Problem

  1. Register with USACO Training Program @ http://train.usaco.org/usacogate/.
  2. Read “Section 1.0 Text Introduction” and “Section 1.1 Submitting Solutions”.
    As mentioned, this site is meant for IOI instead of ICPC, the submission requirements are different from the online judges.
    You are required to read from an input file named “xxxx.in” and write to an output file named “xxxx.out” where “xxxx” is the name of the problem.
    Try the “First Challenge” (or “test” problem). If you encounter problem in File IO under VC++ or Eclipse, read “VC++ File Input/Output” or “Eclipse File Input/Output“, respectively.
    For Java programmers
    The sampled Java solution given is based on JDK 1.2, which is rather clumsy in IO processing. I provide the sample solution in JDK 1.5 is as follows:JDK 1.5 Program Template for USACO

    ID: yourID
    TASK: test
    import java.util.Scanner;
    import java.util.Formatter;
    import java.io.File;
    import java.io.IOException;
    public class test {  // saved as test.java
       public static void main (String [] args) throws IOException {
          Scanner in = new Scanner(new File("test.in"));        // file input
          Formatter out = new Formatter(new File("test.out"));  // file output
          int a = in.nextInt();
          int b = in.nextInt();
          out.format("%d\n",a+b);  // format() has the same syntax as printf()
          out.close();    // flush the output and close the output file
          System.exit(0); // likely needed in USACO
  3. Continue and try to complete the training problem. As mentioned, this site provides systematic training for the frequently used algorithms encountered in contests (IOI as well as ICPC).

Read More: http://www.ntu.edu.sg/home/ehchua/programming/icpc/icpc_getting_started.html


Training ICPC Teams: A Technical Guide
ACM International Collegiate Programming Contest
International Collegiate Programming Contest: Getting Started
Policies and Procedures for the ACM International Collegiate Programming Contest


You may have missed:

Comments are closed.