acm icpc-briefing-prof-nbv

Post on 29-Jul-2015

161 Views

Category:

Engineering

11 Downloads

Preview:

Click to see full reader

TRANSCRIPT

An awareness program on ACM –

ICPC( Programming Competition)

A Briefing Session 1Prof NB Venkateswarlu,

B.Tech, M.Tech(IIT-K), PhD(BITS, Pilani), PDF(U of Leeds, UK)

AITAM, Tekkali

10th March 2015

9.30AM

2

What is ACM?

Internationally, ACM stands for

Association of Computing Machinery

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.  

International Collegiate Programming Contest

(ICPC)

World renowned programming competition.Regionals World Finals

Other Programming Competitions

International Olympiad in Informatics

http://www.ioinformatics.org

Microsoft Imagine Cuphttps://www.imaginecup.co

m

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)!

www.challenge24.org

Where are you great India, so called the mighty IT Giant?

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

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.

How I am qualified for the delivery of this two

day course?

My Books

http://www.amazon.com/dp/

B00T1OK42K

http://www.amazon.com/dp/

B00RFDZT2E

20

ACM Rules…briefly

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

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

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!

24

Sample Scoreboard

2006 ACM Final Scoreboard

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

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)

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)

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

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

Typical ACM Problem Format(1) Problem description

(2) Input description

(3) Output description

(4) Sample input

(5) Sample output

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

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

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

(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

Some Important Concepts

Backtracking Complete Search Dynamic Programming Encryption Game/Puzzle Chess Sudoku Graph Theory Greedy Mathematical

Some Important Concepts

Bases General Geometry Perfect Squares Physics Parsing Straightforward Tree

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

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

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.

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.

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.

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.

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?

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.

STL: Deque

#include <deque> deque<int> x; x.push_back(20); x.pop_back(); x.back();

x.push_front(20); x.pop_front(); x.front(); x.resize(100); x[10] OR x.at(10); x.clear();

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)

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;}

STL: Algorithms

#include <algorithm> Permutations

int x[] = {3, 5, 4, 1, 2};sort(x, x + 5);do {

// stuff} while (next_permutation(x, x + 5));

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

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_spanning_tree– Lots of varying algorithms listed at the bottom of the page

Algorithms (2)

shortest path, like Dijkstra’s algorithm– http://en.wikipedia.org/wiki/

Dijkstra’s_algorithm– http://en.wikipedia.org/wiki/

Shortest_path_problem (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.

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!

Dynamic programming/memoizatio

n• 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

Geometric algorithms

Geometric algorithms

Intersection– Four points: a1, a2, b1, b2– Compute:

• dir1 = direction(b1, b2, a1)• dir2 = direction(b1, b2, a2)• dir3 = direction(a1, a2, b1)• dir4 = direction(a1, a2, b2)

– If dir1/dir2 are opposite signs, and dir3/dir4 are opposite signs, they intersect

a1

a2

b1

b2

dir1

dir2

dir3

dir4

a1

a2

b1

b2

dir1

dir2

dir3

dir4

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!

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.

Some useful online judging sites

www.spoj.com www.wcipeg.com http://acm.pku.edu.cn/JudgeOnline/ icpcres.ecs.baylor.edu/onlinejudge www.iarcs.org.in https://www.hackerrank.com https://www.hackerrank.com

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/

Dictionary of Algorithms and Data Structures maintained by NIST

http://www.nist.gov/dads

Skiena Steven, Stony Brook Algorithm

Repository, http://www.cs.sunysb.edu/~algorith

63

The “Guidebook” Data Structures Strings Sorting Arithmetic Combinatorics Number Theory Backtracking Graph Traversal Graph Algorithms Dynamic Programming Grids Geometry Computational Geometry

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

65

Questions?

66

Session 2

OK, we are going to try some very simple problems!

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=>12=>2 9=>1

Counting characters in a range

• cin >> a >> b;for (i = a; i <= b; ++i){

++arr[i / 10];++arr[i % 10];

}

• 17 21 ?• 21 17 ?

Problem #1 If you have a one-dimensional array of

unsorted number such as0, 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

Solution to HW Problem #1

1. Let input_size = the size of input array2. 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.

3. Sort input array (from smallest value to largest value)

i. Create an empty array of input_size and name it temp

ii. Set value index = 0iii. Find the smallest value in input array and

put it in temp[index]iv. Replace the smallest value with ∞v. index = index + 1vi. 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)

5. Set index_row = index_column = 0, index = input_size-16. do7. 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 >= 011. Return output_array

Solution to HW Problem #1 (iii)

Subroutine next(index, index_row, index_col, input_size, table_size)

1. track_dex = input_size – index -12. If track_dex < 4(table_size-1)

if track_dex < table_size return [index_row, index_col +1]

else if track_dex < 2*table_size – 1 return [index_row+1, index_col]

else if track_dex < 3*table_size – 2 return [index_row, index_col-1]else return [index_row – 1, index_col]

3. Else return next(index-4(table_size-1),index_row, index_col, input_size – 4(table_size-1),table_size – 2);

Session 3

Programming Examples Continued

Session 4 – Recapitulation of

Mathematics

Session – 5Recapitulation of Data

Structures

Session 6Some More Puzzles

Session 7Some More Puzzles

Session 8Some More Puzzles

Any Questions

Thanks

To you The Management The Principal Head, Dr Srinivasarao Garu Mr. Mahesh

top related