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, 2010 (Sat)
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.
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.
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] Delete S[i]: = dist[i-1][j] 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!
Two extensions 1. After filling the table, how to find the steps to change S to T? 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
Problem D. Simulation #include int main () { /* initialize random seed: */ srand ( time(NULL) ); /* generate secret number: */ cout << rand() % ; }
Problem D. Formating #include using namespace std; int main () { double f = ; 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.3, but > 5.2) To be save: add 0.05 first if you need to be correct to 1 decimal place.
Problem E. Flood fill UVA 469, 572