Presentation is loading. Please wait.

Presentation is loading. Please wait.

ACM-HK Local Contest 2009 Special trainings: 6:30 - HW311 May 27, 2010 (Thur) June 3, 2010 (Thur) June 10, 2010 (Thur) Competition date: June 12,

Similar presentations


Presentation on theme: "ACM-HK Local Contest 2009 Special trainings: 6:30 - HW311 May 27, 2010 (Thur) June 3, 2010 (Thur) June 10, 2010 (Thur) Competition date: June 12,"— Presentation transcript:

1 ACM-HK Local Contest 2009 Special trainings: 6:30 - 9pm @ HW311 May 27, 2010 (Thur) June 3, 2010 (Thur) June 10, 2010 (Thur) Competition date: June 12, 2010 (Sat)

2 Today's training Try the problems last year (2009) Each team please use 1 machine only Spend 20 mins to read the questions, tell me who will do which question.

3 Some clarifications needed 1. Question B: How large is x and y? Assume x, y <= 100,000; 2. How many test cases? Assume 10 for each problem.

4 Problem F. Edit distance Well-known example for dynamic programming. Let S[1..m] and T[1..n] be the two input strings. Let dist[i][j] be the edit distance from S[1..i] to T[1..j] (the min steps to change S[1..i] to T[1..j]) AGCG A G C T G Observations. 1. If i==0 or j==0, dist[i][j] = non- zero index. 2. How to convert S[i] to T[j]? 1. Match them: dist[i][j] = dist[i-1][j-1] 2. Substitute S[i] by T[j]: = dist[i-1][j-1] + 1 3. Delete S[i]: = dist[i-1][j] + 1 4. Insert T[j]: = dist[i][j-1] + 1 By trying all 4 cases, I must be able to find the optimal way to change S to T!

5 Two extensions 1. After filling the table, how to find the steps to change S to T? 01234 10123 21012 32101 43211 54321 AGCG A G C T G 2. Given S[1..m] and T[1..n], a subsequence of S is a sequence obtained by deleting some char. A common subsequence is a subsequence common to both S and T. How to find the length of the longest common subsequence? 3. Assignment: UVA 164, 10192, 10066

6 Problem D. Simulation #include int main () { /* initialize random seed: */ srand ( time(NULL) ); /* generate secret number: */ cout << rand() % 10 + 1; }

7 Problem D. Formating #include using namespace std; int main () { double f =123.14159; cout << fixed; cout << setprecision (3) << f << endl; cout << setprecision (9) << f << endl; } setprecision(n): print n decimal places fixed: print trailing zero Rounding? It tries to do 4-down 5-up, but may be incorrect due to precision error. (e.g., 3.25 -> 3.3, but 5.25 -> 5.2) To be save: add 0.05 first if you need to be correct to 1 decimal place.

8 Problem E. Flood fill UVA 469, 572


Download ppt "ACM-HK Local Contest 2009 Special trainings: 6:30 - HW311 May 27, 2010 (Thur) June 3, 2010 (Thur) June 10, 2010 (Thur) Competition date: June 12,"

Similar presentations


Ads by Google