acm-hk local contest 2009 special trainings: 6:30 - 9pm @ hw311 may 27, 2010 (thur) june 3, 2010...
TRANSCRIPT
ACM-HK Local Contest 2009Special trainings:6:30 - 9pm @ HW311May 27, 2010 (Thur)June 3, 2010 (Thur)June 10, 2010 (Thur)
Competition date:June 12, 2010 (Sat)
Today's trainingTry the problems last year (2009)Each team please use 1 machine onlySpend 20 mins to read the questions, tell
me who will do which question.
Some clarifications needed1. 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 distanceWell-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])
A G C G
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!
Two extensions1. After filling the table, how to find the steps to
change S to T?
0 1 2 3 4
1 0 1 2 3
2 1 0 1 2
3 2 1 0 1
4 3 2 1 1
5 4 3 2 1
A G C G
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 <iostream>#include <cstdlib>#include <ctime>int main () { /* initialize random seed: */ srand ( time(NULL) ); /* generate secret number: */ cout << rand() % 10 + 1;}
Problem D.Formating
#include <iostream> #include <iomanip> 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 placesfixed: print trailing zeroRounding? 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.
Problem E. Flood fillUVA 469, 572