How to win in ACM/ICPC? 2011-09-14. Four levels of programmers 1. Implementation ◦ know the language well, translate idea to programs 2. Algorithms ◦

Slides:



Advertisements
Similar presentations
Lecture 24 MAS 714 Hartmut Klauck
Advertisements

Greedy Algorithms.
Introduction to Algorithms Greedy Algorithms
Comments We consider in this topic a large class of related problems that deal with proximity of points in the plane. We will: 1.Define some proximity.
Michael Alves, Patrick Dugan, Robert Daniels, Carlos Vicuna
BackTracking Algorithms
Lecture 3: Parallel Algorithm Design
1.1 Data Structure and Algorithm Lecture 6 Greedy Algorithm Topics Reference: Introduction to Algorithm by Cormen Chapter 17: Greedy Algorithm.
Greed is good. (Some of the time)
Greedy Algorithms Be greedy! always make the choice that looks best at the moment. Local optimization. Not always yielding a globally optimal solution.
Greedy Algorithms Basic idea Connection to dynamic programming
S. J. Shyu Chap. 1 Introduction 1 The Design and Analysis of Algorithms Chapter 1 Introduction S. J. Shyu.
By Groysman Maxim. Let S be a set of sites in the plane. Each point in the plane is influenced by each point of S. We would like to decompose the plane.
Greedy Algorithms Basic idea Connection to dynamic programming Proof Techniques.
Approaches to Problem Solving greedy algorithms dynamic programming backtracking divide-and-conquer.
Delaunay Triangulation Computational Geometry, WS 2006/07 Lecture 11 Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik Fakultät.
1 Lecture 8: Voronoi Diagram Computational Geometry Prof. Dr. Th. Ottmann Voronoi Diagrams Definition Characteristics Size and Storage Construction Use.
Sum of Subsets and Knapsack
CS333 Algorithms
1 Greedy Algorithms. 2 2 A short list of categories Algorithm types we will consider include: Simple recursive algorithms Backtracking algorithms Divide.
1 -1 Chapter 1 Introduction Why Do We Need to Study Algorithms? To learn strategies to design efficient algorithms. To understand the difficulty.
Lecture 10 : Delaunay Triangulation Computational Geometry Prof. Dr. Th. Ottmann 1 Overview Motivation. Triangulation of Planar Point Sets. Definition.
Chapter 9: Greedy Algorithms The Design and Analysis of Algorithms.
Dynamic Programming Optimization Problems Dynamic Programming Paradigm
Chapter 11: Limitations of Algorithmic Power
Greedy Algorithms Like dynamic programming algorithms, greedy algorithms are usually designed to solve optimization problems Unlike dynamic programming.
Introduction Outline The Problem Domain Network Design Spanning Trees Steiner Trees Triangulation Technique Spanners Spanners Application Simple Greedy.
1 Dynamic Programming Jose Rolim University of Geneva.
CPSC 411, Fall 2008: Set 4 1 CPSC 411 Design and Analysis of Algorithms Set 4: Greedy Algorithms Prof. Jennifer Welch Fall 2008.
10/31/02CSE Greedy Algorithms CSE Algorithms Greedy Algorithms.
10/31/02CSE Greedy Algorithms CSE Algorithms Greedy Algorithms.
ACM Programming Contests
Lecture 23. Greedy Algorithms
ACM Programming Contests Coordinator: Dr. Hubert Chan Coach: Luyi Mo Training Holder: Jonathan So Website: i.cs.hku.hk/~provinci.
Software Testing. 2 CMSC 345, Version 4/12 Topics The testing process  unit testing  integration and system testing  acceptance testing Test case planning.
Télécom 2A – Algo Complexity (1) Time Complexity and the divide and conquer strategy Or : how to measure algorithm run-time And : design efficient algorithms.
Recursion. Hanoi Tower Legend: Inside a Vietnamese temple there are three rods (labeled as r 1, r 2, and r 3 ), surrounded by n golden disks of different.
ACM programming contest Introduction + Recursion.
CSC 211 Data Structures Lecture 13
Greedy Methods and Backtracking Dr. Marina Gavrilova Computer Science University of Calgary Canada.
On Graphs Supporting Greedy Forwarding for Directional Wireless Networks W. Si, B. Scholz, G. Mao, R. Boreli, et al. University of Western Sydney National.
Honors Track: Competitive Programming & Problem Solving Optimization Problems Kevin Verbeek.
Models in I.E. Lectures Introduction to Optimization Models: Shortest Paths.
Dynamic Programming Louis Siu What is Dynamic Programming (DP)? Not a single algorithm A technique for speeding up algorithms (making use of.
Lectures on Greedy Algorithms and Dynamic Programming
Provinci summer training 2010 June 17: Recursion and recursive decent parser June 24: Greedy algorithms and stable marriage July 1: Holiday July 8: Math.
Approaches to Problem Solving greedy algorithms dynamic programming backtracking divide-and-conquer.
CS Class 22 Today  A word from the Real World What happens when software goes bad…  Binary Search Announcements  Exam 3 – Nov. 25 th in class.
UNC Chapel Hill M. C. Lin Delaunay Triangulations Reading: Chapter 9 of the Textbook Driving Applications –Height Interpolation –Constrained Triangulation.
Analysis & Design of Algorithms (CSCE 321)
© The McGraw-Hill Companies, Inc., Chapter 1 Introduction.
Copyright © 2014 Curt Hill Algorithms From the Mathematical Perspective.
Lecture. Today Problem set 9 out (due next Thursday) Topics: –Complexity Theory –Optimization versus Decision Problems –P and NP –Efficient Verification.
TU/e Algorithms (2IL15) – Lecture 3 1 DYNAMIC PROGRAMMING
CS Class 04 Topics  Selection statement – IF  Expressions  More practice writing simple C++ programs Announcements  Read pages for next.
Honors Track: Competitive Programming & Problem Solving Seminar Topics Kevin Verbeek.
Introduction to Programming Lecture 12. Today’s Lecture Includes Strings ( character arrays ) Strings ( character arrays ) Algorithms using arrays Algorithms.
CMPS 3130/6130 Computational Geometry Spring 2017
Greedy Technique.
MA/CSSE 473 Day 16 Answers to your questions Divide and Conquer
Courtsey & Copyright: DESIGN AND ANALYSIS OF ALGORITHMS Courtsey & Copyright:
Lecture 22 Complexity and Reductions
Greedy Algorithms / Interval Scheduling Yin Tat Lee
Introduction to Algorithms
Design and Analysis of Computer Algorithm (CS575-01)
Advanced Analysis of Algorithms
Trevor Brown DC 2338, Office hour M3-4pm
Time Complexity and the divide and conquer strategy
Lecture 22 Complexity and Reductions
Data Structures and Algorithms
Presentation transcript:

How to win in ACM/ICPC?

Four levels of programmers 1. Implementation ◦ know the language well, translate idea to programs 2. Algorithms ◦ Design good solutions 3. Software engineering ◦ manage different components and people 4. World ◦ How can I change the world?

How to win in ACM/ICPC? Be excellent in implementation and algorithms Important warning! ACM cannot test your ability beyond algorithms To change the world requires many more things. See the bigger picture and keep learning. Implementation and algorithms are necessary, but they are not the end. :)

What kind of implementation skills are needed? Variables, loops, functions Exhaustion ◦ Try all permutations ◦ Try all subsets ◦ Try all paths, etc Classes, operator overloading, STL Persistence (don't be afraid of long problems and programs)

Example. POJ 1564 Given a target T and an integer array A[1..n] (with possible repetition), find all subsets of A that sum to T //A[0..n] is descending //B[0..m] is selected void gen( int A[], int n, int B, int m, int T, int skip ){ if( target==0 ){ //output B, return } if( n==0 ) return; if( A[0]>target || skip==A[0] ){ gen( A+1, n-1, B, m, T, skip ); }else{ //try to pick A[0] B[m] = input[0]; m++; gen( A+1, n-1, B, m, T-A[0], skip ); //try not to pick A[0] m--; gen( A+1, n-1, B, m, T, input[0] ); }

Example. POJ 1146 Given a string s. Rearrange the characters to s' so that s' is just lexicographically larger than s. ◦ E.g., abc -> acb, acba -> baac string s; cin >> s; next_permutation( s.begin(), s.end() ); cout << s; Time complexity? O(n) If called n! times, O(n!) time

Examples. How to read a line of integers (where the number of integers are unknown)? How to sort integers in descending order? string line; getline( cin, line ); stringstream ss( line ); int i; while( ss >> i ) cout << i << endl; int a[100]; sort( a, a+100, greater () );

How to improve implementation? Write more programs Read more books Don't afraid of new tools ◦ STL ◦ Debugger Exercises. 1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008, 1010, 1012, 1013, 1016, 1019

Algorithmic skills (1/4)? 1. Standard algorithm design principles ◦ Divide-and-conquer ◦ Dynamic programming  Save up the partial results  The optimal solution can be found by backtracking ◦ Greedy  Sometimes the seemingly best choice is the only best choice These are principles that we don't need to memorize

Example. POJ1015 Given m jury members and to select n, each with p i, d i. Find a subset that minimizes |∑p i - ∑d i |. What can we achieve if we select r from the first k jury members? possible[0..200][0..20][ ]: where possible[k][r][d] = 1 if we can select r from first k jury members and achieve diff = d

Example. POJ1024 Given a 2D map, decide whether there is a unique path from s to t. Calculate the shortest path to each position by DP. Then do backtracking to see if the path is unique.

Example. POJ1018 We need to build a channel with n parts. Part i has c i choices (b i1, p i1 ), (b i2,p i2 ) Final bandwidth = min bandwidth of a part. Final cost = total cost Find maximum B/P For each possible B, the minimum cost is formed by picking the choice with b >= B and minimum price.

Algorithmic skills (2/4)? 2. Running time analysis

Algorithmic skills (3/4)? 3. Observation and creativity ◦ Find some properties about the problem

Example. POJ1021 Given two 2D objects. Determine if they have the same shape under rotation or reflection. Start from the top left position, do a flooding and record the path. Compare if the two paths are the same. string fill( int x, int y, string path ){ if( visited[x][y] ){ path += 'E'; return s; } visited[x][y] = true; path += '.'; s = fill( x-1, y, s ); //repeat 4 times return s; }

Example. POJ1009 Given a run length encoded 2D board. Transform each cell to max{ diff with 8 direction }. Output the run length encoded 2D board. Label the cell linearly. Observation. If all of i's neighbors are not start or end of a new segment. Then the value of i equals the value of i-1.

Break 1. Standard algorithm design principles 2. Running time analysis 3. Observation and creativity ◦ Find some properties about the problem How to improve creativity? ◦ Be imaginative. ◦ Try to indentify properties of the problem.

Algorithmic skills (4/4)? 4. Common algorithms ◦ Algorithms that have been studied before. ◦ Memorize the algorithms ◦ Sorting, graphs, network flow, coordinate geometry, math Be hardworking, read more books

Example. POJ3391 Given n points on a 2D coordinate plane. Find the minimum spanning tree. I try to teach you an average O( n log n ) time algorithm.

Delaunay Triangulation Definition. Given a set of points in 2D. A triangulation is a division of the convex hull so that all regions are triangles. Definition. A Delaunay triangulation is a triangulation so that each circumcircle contains no points in the in interior.

Immediate questions Does a Delaunay triangulation always exist? How is it related to finding spanning tree? How to find the Delaunay triangulation efficiently?

Delaunay triangulation and minimum spanning tree Theorem. The minimum spanning tree containing only edges in the Delaunay Triangulation.

Other applications Theorem. The closest neighbor of each point p is its Delaunay neighbor. Theorem. The point within the convex hull that is furthest from any other point is the circumcenter of a Delaunay triangle.

Slow algorithm. Edge flip Theorem. We can continue to remove illegal triangle and the resulting triangulation is Delaunay.

Fast Algorithm p 0 = the top-right site, p -1 = (∞, -∞), p -2 = (-∞, ∞) be the initial triangle. Random shuffle the remaining sites. For each remaining point p ◦ Find the triangle containing p ◦ Only new triangle may violate Delaunay property

The legalizeTriangle Legalize( p, pi, pj, pk ){ if( pipj is ilegal ) flip pipj and ppk Legalize( p, pipk, pi' ); Legalize( p, pjpk, pj' ); }

Find triangle containing p

Schedule for this year MonTueWedThurFri 5/9 12/9HL 19/9 26/9 Individual contest 3/10 10/10 Team contest 17/10 Team contest Possible regionals: Kuala Lumpur (Nov ) or Hsinchu (Nov26)

Summary Implementation ◦ Persistence Algorithms ◦ Running time analysis ◦ Design techniques ◦ Observation and creativity ◦ Common algorithms Prepare for internal contest and regional Algorithms != software