Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Acm icpc-briefing-prof-nbv

1,410 views

Published on

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.

Published in: Engineering
  • Be the first to comment

Acm icpc-briefing-prof-nbv

  1. 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. 2 What is ACM?  Internationally, ACM stands for Association of Computing Machinery
  3. 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.
  4. 4. International Collegiate Programming Contest (ICPC) World renowned programming competition. Regionals  World Finals
  5. 5. Other Programming Competitions
  6. 6. International Olympiad in Informatics http://www.ioinformatics.org
  7. 7. Microsoft Imagine Cup https://www.imaginecup.com
  8. 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)!
  9. 9. www.challenge24.org
  10. 10. Where are you great India, so called the mighty IT Giant?
  11. 11. 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?
  12. 12. 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.
  13. 13. How I am qualified for the delivery of this two day course?
  14. 14. My Books
  15. 15. http://www.amazon.com/dp/ B00T1OK42K
  16. 16. http://www.amazon.com/dp/ B00RFDZT2E
  17. 17. 20 ACM Rules…briefly
  18. 18. 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
  19. 19. 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
  20. 20. 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!
  21. 21. 24 Sample Scoreboard 2006 ACM Final Scoreboard
  22. 22. 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
  23. 23. 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)
  24. 24. 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)
  25. 25. 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
  26. 26. 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!
  27. 27. 30 Typical ACM Problem Format (1) Problem description (2) Input description (3) Output description (4) Sample input (5) Sample output
  28. 28. 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
  29. 29. 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
  30. 30. 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.
  31. 31. 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
  32. 32. Some Important Concepts  Backtracking  Complete Search  Dynamic Programming  Encryption  Game/Puzzle  Chess  Sudoku  Graph Theory  Greedy  Mathematical
  33. 33. Some Important Concepts  Bases  General  Geometry  Perfect Squares  Physics  Parsing  Straightforward  Tree
  34. 34. 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
  35. 35. 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
  36. 36. 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.
  37. 37. 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.
  38. 38. 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.
  39. 39. 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.
  40. 40. 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?
  41. 41. 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.
  42. 42. 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();
  43. 43. 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)
  44. 44. 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; }
  45. 45. STL: Algorithms  #include <algorithm>  Permutations int x[] = {3, 5, 4, 1, 2}; sort(x, x + 5); do { // stuff } while (next_permutation(x, x + 5));
  46. 46. 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
  47. 47. 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
  48. 48. 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.
  49. 49. 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!
  50. 50. 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
  51. 51. Geometric algorithms
  52. 52. 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
  53. 53. a1 a2 b1 b2 dir 1 dir 2 dir 3 dir 4 a1 a2 b1 b2 dir 1 dir 2 dir 3 dir 4
  54. 54. 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!
  55. 55. 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.
  56. 56. 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
  57. 57. 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/
  58. 58. Dictionary of Algorithms and Data Structures maintained by NIST  http://www.nist.gov/dads
  59. 59. Skiena Steven, Stony Brook Algorithm Repository,  http://www.cs.sunysb.edu/~algorith
  60. 60. 63 The “Guidebook”  Data Structures  Strings  Sorting  Arithmetic  Combinatorics  Number Theory  Backtracking  Graph Traversal  Graph Algorithms  Dynamic Programming  Grids  Geometry  Computational Geometry
  61. 61. 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
  62. 62. 65 Questions?
  63. 63. 66 Session 2 OK, we are going to try some very simple problems! 
  64. 64. 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
  65. 65. Counting characters in a range • cin >> a >> b; for (i = a; i <= b; ++i) { ++arr[i / 10]; ++arr[i % 10]; } • 17 21 ? • 21 17 ?
  66. 66. 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
  67. 67. 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)
  68. 68. 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)
  69. 69. 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)
  70. 70. Subroutine next(index, index_row, index_col, input_size, table_size) 1. track_dex = input_size – index -1 2. 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] 1. Else return next(index-4(table_size-1),index_row, index_col, input_size – 4(table_size- 1),table_size – 2);
  71. 71. Session 3  Programming Examples Continued
  72. 72. Session 4 – Recapitulation of Mathematics
  73. 73. Session – 5 Recapitulation of Data Structures
  74. 74. Session 6 Some More Puzzles
  75. 75. Session 7 Some More Puzzles
  76. 76. Session 8 Some More Puzzles
  77. 77. Any Questions
  78. 78. Thanks  To you  The Management  The Principal  Head, Dr Srinivasarao Garu  Mr. Mahesh

×