This presentation briefs about International Collegiate Programming Contest(ICPC) which is organized by ACM and sponsored by IBM.
This is delivered at VB Siddardha Colleges, Vijayawada on 10th Mar 2015. Somehow Indian participation is not attractive. I am encouraging Indian students to participate in this competition by delivering lectures like this.
1. An awareness program on
ACM –ICPC( Programming
Competition)
A Briefing Session 1
Prof NB Venkateswarlu,
B.Tech, M.Tech(IIT-K), PhD(BITS, Pilani), PDF(U of Leeds, UK)
AITAM, Tekkali
10th
March 2015
9.30AM
2. 2
What is ACM?
Internationally, ACM stands for
Association of Computing Machinery
3. About ACM
ACM, the Association for Computing Machinery
www.acm.org, is the world’s largest
educational and scientific computing society,
uniting computing educators, researchers and
professionals to inspire dialogue, share
resources and address the field’s challenges.
ACM strengthens the computing profession’s
collective voice through strong leadership,
promotion of the highest standards, and
recognition of technical excellence. ACM
supports the professional growth of its
members by providing opportunities for life-long
learning, career development, and professional
networking.
8. 8
Annual Code Match (ACM)
We borrowed the acronym 'ACM' and made it
Annual Code Match
The IBM-Annual Code Match 2006 & 2007
– Modelled after ACM-ICPC, but held at university-level,
closed doors
– Sponsored by IBM Malaysia
– http://fit.mmu.edu.my/codematch
The winning teams were sponsored to ACM-
ICPC Asia Regionals in Manila (Oct 2006) and
Singapore (Dec 2007)!
10. Where are you great India, so
called the mighty IT Giant?
11.
12.
13. 13
Why take part in competitions?
Develop your problem-solving skills
To break Google, FB, Yahoo, Amazon Interviews and
earn 1.7Cr package and gloom in News Papers and
bring fame to your parents, and to your college,
To win some cash $$ or prizes.
An opportunity to represent the university in various
competitions if selected
…and normally that's fully sponsored!
It’s where you can demonstrate what you are really
capable of
Learn to compete seriously!
Good for your CV?
14. 14
Why this two day course is
organized?
Find the cream of the crop...to represent your
Institute in future competitions (Especially ACM-
ICPC)
Develop a problem-solving 'culture' among our
students
Provide the talented students a platform to
increase their potentials (forget about the
classroom...)
Stone sharpens stone
ALSO TO KNOW YOUR INTEREST TO
CONTINUE THIS ACTIVITY.
15. How I am qualified for the
delivery of this two day
course?
21. 21
ACM Rules
Languages: C, C++, Java
Each team will be provided with 1 computer
usually with Linux
Allowed to bring in 25 pages of notes
Contest will be run for 5 hours
– Food and drinks will be normally provided
Number of questions: 7-10
Contest is conducted using PC2
system
– Submission of answers
– Clarification
– Judging (human and/or computer judge)
– Live scoreboard
22. 22
Scoring System
Solutions to problems submitted are called runs.
Teams are ranked according to most problems
solved
Teams that solve the same number of problems
are ranked by
– Least total time
– Earliest time of submittal of last accepted run
23. 23
Scoring System
Total time = Sum of time consumed for each
problem
Time consumed = Time elapsed from beginning
of contest to submittal of accepted run
Each rejected run: +20 penalty minutes
No time is consumed for an unsolved problem
Output must be exactly same as required
format, otherwise considered wrong!
25. Submitting
• You will receive one of several responses:
– Format error
– Time limit reached
– Runtime error (division by 0, out of memory,
exception thrown, etc.)
– Compile error
– Wrong answer
– Correct!
• The judges only give you one at a time
– If you have two or more problems, you’ll usually
only get the more embarrassing of them
26. Always have someone typing
• Typing and compiling is time intensive, and
there’s only one keyboard
– If your program isn’t working, print it and debug
it by hand
– Let someone else sit and type!
• If you’re waiting for the computer, write
some code out by hand or ask a neighbor
for their opinion on your algorithm
• If it has you read until end of input, use:
while (cin >> x)
27. Questions
You can submit questions to the judges
about problems
Updates will be given to everyone if
there is a typo or other error
You will get one of two responses:
– A clarification
– No answer (i.e. read the problem more
closely)
28. Test the judge’s input
They give you 1 or 2 sample inputs and
solutions; test them!
– There will normally be simple cases.
Make sure your format exactly matches
the judge’s sample output!
– They use a file compare (via a script) so it
must be very close
29. End cases
The judges are very tricky with their tests
If the problem says inputs will be
between A and B, you can almost bet
that inputs of size A and B will be tested
Be wary of carefully worded questions!
30. 30
Typical ACM Problem Format
(1) Problem description
(2) Input description
(3) Output description
(4) Sample input
(5) Sample output
31. 31
Standard I/O technique
Input stream has to be continuously inputted
with data (number, char, string, etc.) until it
finishes.
Output will show all that has been processed.
May not be the best way to test your codes, but
it is required for submission.
Use Input File Piping technique for easier
testing & debugging of data
32. 32
Sample Problem
Finding the absolute difference between 2
numbers
Demo
– Standard “continuous” I/O (for submission of solution)
– Input File Piping (for testing/debugging)
Sample Input:
3 7
2 -2
Sample Output:
4
4
33. 33
File Reading – Not often
Possibly need to do file reading if the problems
require you to specifically use a certain name of
input text file such as “data.txt”, but this is rare.
34. 34
(PC)2
Submission System
Software for teams to submit their answers for
evaluation. Result feedback (Accepted or
Rejected with specific reason) is quite fast.
Software allows teams to test (compile and run)
their answers with the server environment.
Answers are evaluated with judges' own set of
test data
35. Some Important Concepts
Backtracking
Complete Search
Dynamic Programming
Encryption
Game/Puzzle
Chess
Sudoku
Graph Theory
Greedy
Mathematical
36. Some Important Concepts
Bases
General
Geometry
Perfect Squares
Physics
Parsing
Straightforward
Tree
37. Be generous with your
memory!
Make your arrays twice as big as
necessary
– Off by one error are difficult to find!
Use the STL (strings, vectors,
everything!)
Use long long instead of int
Use double instead of float
38. Code quickly at the cost of
efficiency
The faster you type, the faster you
submit!
Use the STL if it makes it easier for you
– If you can’t remember how to use the STL
sort, write a simple (bubble?)sort. Who
cares!
Generally, if you get a “time limit
reached”, your algorithm needs to be
changed, not just little things in your
code
39. Helpful suggestion
Bring printed code, such as the
algorithms we’ll talk about.
• You won’t have to remember them and know
you have a working/correct version too.
– If someone is not typing in an answer, type
in the algorithm so the template is ready to
use.
– Also data structures you may want to use
(trees for example).
– Including a “read a file” code. You know it
works, then one least thing to think about.
40. math
Number theory
– Very popular in the program contests
– For ICPC, you need a rather small but
useful set
• Prime table generation, primality testing,
greatest common divisor, modular arithmetic
and congruence (solving linear congruences),
and Euler’s
– A Note, Java’s BigInteger class has a
number of number-theoretic functions, like
gcd, modular exponentiation, primality
testing, etc.
41. String manipulation
There have been a number of string
manipulation questions over the years.
Learn the string library
– At the least substring, replace, find etc.
– Regex maybe really helpful.
42. algorithms
Brute force algorithms
– From nested loop algorithms to backtracking
(easier with recursion).
• Breath first search.
• Depth first search is recursive and has nice
bracktracking features.
Dynamic Programming
– Recursive algorithm that is composed of
subproblems
• Coin flipping and fibonacci are simple examples
• Longest Common Subsequence (LCS), Longest
Increasing Subsequence (LIS), Optimal Binary
Search tree (OBST), 0-1 knapsack, edit distance,
Matrix Chain Product are increasing harder
examples.
43. algorithms
Trees and priority queues, not necessary
an algorithms, but can speed things up.
Graph theory
– How to represent things and then use BFS
and DFS, and topological sorting.
• Does the graph have cycles?
44. Classic Problems algorithms
Shortest paths (Dijkstra for example)
Spanning trees (Prim or Kruskal)
Eulerain paths and circuits
Matchings in bipartite graphs
Network flow (max flow, min cost flows)
Geometry.
46. STL: Strings
• #include <string>
• string str; string str(“foo”); string str(10, ‘c’);
• str += “bar”;
• Find
– str.find(“aaba”); str.rfind(“aaba”);
– str.find_first_of(“AEIOU”);
– str.find_last_not_of(“AEIOU”, 5);
– Returns an int, or string::npos if none found
• str.substr(int position, int length)
47. STL: Algorithms
• #include <algorithm>
• swap(a, b); // Any type that has = can go here!
• reverse(arr, arr + 10);
reverse(deq.begin(), deq.end());
• Sorting
– sort(arr, arr + 10); sort(deq.begin(), deq.end());
– sort(arr, arr + 10, lessThanFunction);
bool lessThanFunction(const Type& t1, const
Type& t2)
{
if (t1 < t2)
return true;
return false;
}
48. STL: Algorithms
#include <algorithm>
Permutations
int x[] = {3, 5, 4, 1, 2};
sort(x, x + 5);
do {
// stuff
} while (next_permutation(x, x + 5));
49. STL: formatting
• #include <iomanip>
• double d = 12345.6789;
• cout << d << endl;
• cout << setprecision(3) << d << endl;
• cout << setprecision(3) << fixed << d << endl;
• cout << setprecision(1) << fixed << 0.55 <<
endl;
• int i = 42;
• cout << hex << i << endl;
• cout << hex << uppercase << i << endl;
• cout << i << endl;
• cout << dec << i << endl;
• 12345.7
• 1.23e+04
• 12345.679
• 0.6
• 2a
• 2A
• 2A
• 42
50. Algorithms
Brush up on
– depth-first search, breadth-first search (or just
use iterative deepening DFS)
• N-Trees, but lots of other uses as well.
minimum spanning trees
http://en.wikipedia.org/wiki/Minimum_span
ning_tree
– Lots of varying algorithms
listed at the bottom of the page
51. Algorithms (2)
shortest path, like Dijkstra’s algorithm
– http://en.wikipedia.org/wiki/Dijkstra’s_algorit
hm
– http://en.wikipedia.org/wiki/Shortest_path_pr
oblem
(Max) flow problems
– http://www-b2.is.tokushima-
u.ac.jp/~ikeda/suuri/maxflow/Maxflow.shtml
• Good demo of max flow and min cut algorithms.
• Also links to some other versions of spanning
tree algorithms.
52. Algorithms (3)
Greatest common divisor is a fun one to
remember too
– And remember, if gcd(a, b) == 1, then a and
b are relatively prime!
53. Dynamic
programming/memoization
• Recursive algorithm that is composed of
subproblems
– You keep recomputing the subproblems!
– Save them in an array and look them up
– Start with the recursive version first, then
modify it to save work
• Examples
– Fibonacci
– Coin problem
57. 57
Debunking some myths
I know C, C++, C#, Java, Pascal, Perl, Python,
LISP,… I don’t think I have much problem with
programming!
Good in programming == Good in problem solving
Look, I know how to solve this problem on paper!
In ACM, programming is just a tool
Can you code it?
!=
Here, we want to solve problems, not write nice programs
I can write a really nice program, with neat
functions and classes you know!
58. Some Important Difficulties
of students. Most students do not perform well under limited time
pressure. This hinders their performance not only in
programming competitions, but also in employment
interviews that focus on immediate problem solving.
Students have difficulty with the analysis of new
problems and being able to select an appropriate
algorithm.
Students often have difficulty expressing their point of
view on how a problem should be solved. They might
lack confidence or communication skills, or they may
not have experience in explaining the workings of an
algorithm.
Students at the Junior year level have had little or no
exposure to teamwork in a problem solving context.
60. 60
Useful Resources
“Programming Challenges: The Programming Contest
Training Manual” by Steven Skiena & Miguel Revilla
– http://fit.mmu.edu.my/codematch/acm_downloads.php
UVA Problemset Archive – favourite spot for people to
train for ACM contests
– http://uva.onlinejudge.org/
– PLEASE register an account and try out the problems!
ACM-ICPC Live Archive – past year regional/world final
questions
– http://acmicpc-live-archive.uva.es/nuevoportal/
63. 63
The “Guidebook”
Data Structures
Strings
Sorting
Arithmetic
Combinatorics
Number Theory
Backtracking
Graph Traversal
Graph Algorithms
Dynamic Programming
Grids
Geometry
Computational Geometry
64. 64
Some things to kickstart…
Register in mmu-acm Google Group – for
communication, discussion, sharing
– http://groups.google.com/group/mmu-acm
– Invitation will be sent out soon…
You may work closely with people whom you’re
comfortable with. Teamwork can be forged early.
Continue to sharpen your programming skills
Learn useful algorithms for problem-solving
67. Counting characters in a
range
• Input will consist of two integers, 0 < N <
100
• For each of the numbers in between these
two numbers (inclusive), count the
occurrences of each digit
• Example: 17 21
– 17 18 19 20 21
– 0=>1 7=>1
1=>4 8=>1
2=>2 9=>1
68. Counting characters in a
range
• cin >> a >> b;
for (i = a; i <= b; ++i)
{
++arr[i / 10];
++arr[i % 10];
}
• 17 21 ?
• 21 17 ?
69. Problem #1
If you have a one-dimensional array of
unsorted number such as
0, 9, 3, 15, 4, 11, 25, 3, 0
Convert it into a two-dimensional array
whose numbers of row and column are
equal, such that the largest element is at
the top left corner, and continue to put the
next largest element in-ward in a clock-
wise manner
25 15 11
0 0 9
3 3 4
70. Solution to HW Problem #1
1. Let input_size = the size of input array
2. table_size = ceil(sqrt(input_size))
– Note that ceil() is the function that rounds
the input number to the nearest integer
greater than the input number
– sqrt() is the square root function.
1. Sort input array (from smallest value to
largest value)
71. i. Create an empty array of input_size and
name it temp
ii. Set value index = 0
iii. Find the smallest value in input array and
put it in temp[index]
iv. Replace the smallest value with ∞
v. index = index + 1
vi. Repeat from iii to vi until index ==
input_size
4. Create 2-dimensional array of
table_size*table_size named
output_array
Solution to HW Problem #1 (ii)
72. 5. Set index_row = index_column = 0,
index = input_size-1
6. do
7. output_array[index_row][index_column]
= temp[index]
8. [index_row, index_column] = next(index,
input_size, table_size)
9. index = index – 1;
10. While index >= 0
11. Return output_array
Solution to HW Problem #1 (iii)