hkucs provinci training 2011-07-13 agenda: 3:00pm-4:25pm: solution of selection contest...

11
HKUCS Provinci HKUCS Provinci Training Training 2011-07-13 2011-07-13 Agenda: 3:00pm-4:25pm: Solution of Selection Contest 4:25pm-4:35pm: 10-minute break 4:35pm-6:00pm: Programming Practice Speaker: Niels Tsang

Upload: phillip-hunt

Post on 26-Dec-2015

214 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: HKUCS Provinci Training 2011-07-13 Agenda: 3:00pm-4:25pm: Solution of Selection Contest 4:25pm-4:35pm: 10-minute break 4:35pm-6:00pm: Programming Practice

HKUCS Provinci TrainingHKUCS Provinci Training2011-07-132011-07-13

Agenda:3:00pm-4:25pm: Solution of Selection Contest4:25pm-4:35pm: 10-minute break4:35pm-6:00pm: Programming Practice

Speaker:Niels Tsang

Page 2: HKUCS Provinci Training 2011-07-13 Agenda: 3:00pm-4:25pm: Solution of Selection Contest 4:25pm-4:35pm: 10-minute break 4:35pm-6:00pm: Programming Practice

Selection Contest (2011-07-Selection Contest (2011-07-05)05)Problem 1: CANDY (8/8 solved)Problem 2: THRBL (4/8 solved)Problem 3: COINS (7/8 solved)Problem 4: AGGRCOW (3/8

solved)Problem 5: BASE (7/8 solved)Problem 6: BABTWR (4/8 solved)Problem 7: WORD (0/8 solved)

Page 3: HKUCS Provinci Training 2011-07-13 Agenda: 3:00pm-4:25pm: Solution of Selection Contest 4:25pm-4:35pm: 10-minute break 4:35pm-6:00pm: Programming Practice

Problem 1: CANDY (8/8 Problem 1: CANDY (8/8 solved)solved)SPOJ 2123 - Candy I (Problem code:

CANDY)Problem Type: Ad hochttp://www.spoj.pl/problems/CANDY/

Hint:Calculate the average of the integersMake use of greedy concept

Page 4: HKUCS Provinci Training 2011-07-13 Agenda: 3:00pm-4:25pm: Solution of Selection Contest 4:25pm-4:35pm: 10-minute break 4:35pm-6:00pm: Programming Practice

Problem 5: BASE (7/8 Problem 5: BASE (7/8 solved)solved) SPOJ 870 - Basically Speaking (Problem code:

BASE) Problem Type: Base number conversion http://www.spoj.pl/problems/BASE/

Hint: Convert the given value to decimal format Convert the decimal value to target format

Page 5: HKUCS Provinci Training 2011-07-13 Agenda: 3:00pm-4:25pm: Solution of Selection Contest 4:25pm-4:35pm: 10-minute break 4:35pm-6:00pm: Programming Practice

Problem 3: COINS (7/8 Problem 3: COINS (7/8 solved)solved) SPOJ 346 - Bytelandian gold coins (Problem code:

COINS) Problem Type: Recursion with memorization http://www.spoj.pl/problems/COINS/

Hint: Use long long type Use map to store the result Use memorization

Page 6: HKUCS Provinci Training 2011-07-13 Agenda: 3:00pm-4:25pm: Solution of Selection Contest 4:25pm-4:35pm: 10-minute break 4:35pm-6:00pm: Programming Practice

Problem 4: AGGRCOW (3/8 Problem 4: AGGRCOW (3/8 solved)solved) SPOJ 297 - Aggressive cows (Problem code:

AGGRCOW) Problem Type: Binary search http://www.spoj.pl/problems/AGGRCOW/

Hint: Make use of Binary Search (non-trivial) Think the lower bound and upper bound first

Page 7: HKUCS Provinci Training 2011-07-13 Agenda: 3:00pm-4:25pm: Solution of Selection Contest 4:25pm-4:35pm: 10-minute break 4:35pm-6:00pm: Programming Practice

Problem 2: THRBL (4/8 Problem 2: THRBL (4/8 solved)solved) SPOJ 8952 - Catapult that ball (Problem code:

THRBL) Problem Type: RMQ (Range Maximum Query)

http://www.spoj.pl/problems/THRBL/

Hint: Fill in a O(nlogn) table2 3 5 4 2 1 6

Level 1

3 5 2

5 4 6

Level 2

5

5

5

6

Page 8: HKUCS Provinci Training 2011-07-13 Agenda: 3:00pm-4:25pm: Solution of Selection Contest 4:25pm-4:35pm: 10-minute break 4:35pm-6:00pm: Programming Practice

Problem 6: BABTWR (4/8 Problem 6: BABTWR (4/8 solved)solved) SPOJ 100 - Tower of Babylon (Problem code: BABTWR) Problem Type: LIS (Longest Increasing Subsequence) http://www.spoj.pl/problems/BABTWR/

Hint: Let OPT[i] be the highest height of blocks[1..i] that ends exactly at

blocks[i] OPT[i] = max( OPT[k] + blocks[i] where k < i and blocks[k] <

blocks[i] ); for i = 1..n OPT[i] = blocks[i]; for k = 1..(i-1) if a[k] < a[i] OPT[i] = max( OPT[i], OPT[k] + blocks[i] ); cout << max( OPT[j] where j = 1..n );

Time Complexity: O(n^2) but O(nlogn) time is feasible

Page 9: HKUCS Provinci Training 2011-07-13 Agenda: 3:00pm-4:25pm: Solution of Selection Contest 4:25pm-4:35pm: 10-minute break 4:35pm-6:00pm: Programming Practice

Problem 6: BABTWR (4/8 Problem 6: BABTWR (4/8 solved)solved) Analysis of sample input: (sort by z in asc order, and then by x in desc order) y x z 83 27 33 -> 83 59 31 41 -> 59 58 26 53 26 53 58 53 26 58 31 41 59 -> 31 41 31 59 84 62 64 -> 84 27 33 83 33 27 83 62 64 84 -> 62 64 62 84 97 23 93 23 93 97 -> 23 93 23 97 ------------------ sum = 342

Page 10: HKUCS Provinci Training 2011-07-13 Agenda: 3:00pm-4:25pm: Solution of Selection Contest 4:25pm-4:35pm: 10-minute break 4:35pm-6:00pm: Programming Practice

Problem 7: WORD (0/8 Problem 7: WORD (0/8 solved)solved)SPOJ 8750 - Wordplay (Problem code:

WORD)Problem Type: Euler pathhttp://www.spoj.pl/problems/WORD/

Hint:

ANBA NA

Page 11: HKUCS Provinci Training 2011-07-13 Agenda: 3:00pm-4:25pm: Solution of Selection Contest 4:25pm-4:35pm: 10-minute break 4:35pm-6:00pm: Programming Practice

Programming PracticeProgramming Practice POJ 1094 – Sorting It All Out http://poj.org/problem?id=1094 POJ 1159 – Palindrome http://poj.org/problem?id=1159 POJ 1330 – Nearest Common Ancestors http://poj.org/problem?id=1330 POJ 2157 – Maze http://poj.org/problem?id=2157 POJ 2446 – Chessboard http://poj.org/problem?id=2446 POJ 3126 – Prime Path http://poj.org/problem?id=3126 POJ 3211 – Washing Clothes http://poj.org/problem?id=3211