Presentation is loading. Please wait.

Presentation is loading. Please wait.

Welcoming Lecture Meeting/Discussion/Party By David/Denon.

Similar presentations


Presentation on theme: "Welcoming Lecture Meeting/Discussion/Party By David/Denon."— Presentation transcript:

1 Welcoming Lecture Meeting/Discussion/Party By David/Denon

2 First of All… Welcome guys Powered by Google Translator

3 Agenda Contest Format Taste the challenges Input /Output STL introduction Admin

4 THE CONTEST ACM ICPC

5 The Contest ACM International Collegiate Programming Contest (abbreviated as ACM-ICPC or just ICPC) is an annual multi-tiered computer programming competition among the universities of the world. The contest is sponsored by IBM. Headquartered at Baylor University, with autonomous regions on six continents, the ICPC is directed by Baylor Professor William B. Poucher, Executive Director, and operates under the auspices of the Association for Computing Machinery (ACM).IBMBaylor University Association for Computing Machinery (From wikipedia)

6 The Contest ● World Finals is held every year. ● To earn the free ticket to this glory battlefield, we need to excel in the Regional competitions. – To be held in late October and November.

7 The Contest Team of three One Computer per team 8 – 13 problems X hours Solve the most problem in the shortest time wins the competition

8 The Contest while ( ! isTimeout() ) { read(); think(); program(); //debug(); submit(); }

9 One Balloon as a gift for solving a problem. Each problem is associated with a color.

10 HOW? Solve Problem

11 Let’s try 10080 - Gopher II 563 - Crimewave This is a interesting problem but solving it requires some knowledge (i.e. max flow) that you may or may not have acquired at the moment. However, in order for you to see what is a typical ICPC problem looks like, just pretend that you know how to solve the problem on the next slide.

12 Let’s Try SoSi 4 1 232 3 4 So = Source Si = Sink

13 Let’s Try SoSi 0/4 0/1 1/21/31/2 0/3 0/4 So = Source Si = Sink Is this a possible setting? Does it violate any constraints?

14 Let’s Try SoSi 0/4 0/1 1/21/31/2 0/3 0/4 So = Source Si = Sink What is the total flow from the Source to the Sink?

15 Let’s Try SoSi 3/4 3/1 4/20/31/2 0/3 0/4 So = Source Si = Sink How about this one? Is it a valid configuration? (2)

16 Let’s Try SoSi 1/4 1/1 2/21/31/2 0/3 0/4 So = Source Si = Sink This is another valid configuration.

17 Max-Flow Problem When given a graph, what is the max. valid flow on it?

18 Max-Flow Problem SoSi 1/4 1/1 1/20/32/2 2/3 0/4 So = Source Si = Sink Max. Flow = 3

19 Max-Flow Problem Now just assume that your teammate know how to program the function() to solve the max-flow problem. Input: (single source, single sink, non-negative constraints) SoSi 4 1 232 3 4

20 Max-Flow Problem Input: (single source, single sink, non-negative constraints) SSi 4 1 232 3 4 Output: (Max total flow, flow on each edge) S Si 1/4 1/1 1/20/32/2 2/3 0/4

21 Max-Flow Problem What if there are multiple sources or/and sinks? How can we use the function() to help solving the problem? (Remember function() can only solve problems of single sources and single sources) So Si 4 1 2 32 3 4 So Si 4 43

22 Max-Flow Problem Transformation S S 4 1 2 32 4 S S 4 43

23 Max-Flow Problem Transformation S Si 4 1 2 32 4 S 4 43 S’ Si’

24 Max-Flow Problem Transformation S S Si 4 1 2 32 4 S S 4 43 S’ Si’

25 Max-Flow Problem Transformation S S Si 4 1 2 32 4 S S 4 43 S’ Si’ infi

26 Can you solve the following problem? 10080 - Gopher II Hints: Use the function() Hints: do a transformation

27 10080 - Gopher II Let’s have 5 mins break. (It is not actually a break. It is expected that you read the problem during this given time) http://uva.onlinejudge.org/index.php?option=c om_onlinejudge&Itemid=8&category=12&pag e=show_problem&problem=1021

28 10080 - Gopher II Hints: Use the function() Hints: do a transformation Hole 5s Away Velocity of Gopher: 1 m/s 3m(3s) 8m(8s) 3m(3s) 8m(8s) 3m(3s)

29 10080 - Gopher II Hints: Use the function() Hints: do a transformation Hole 5s Away Velocity of Gopher: 1 m/s 3m(3s) 8m(8s) 3m(3s) 8m(8s) 3m(3s) The Constraint is 1 Gopher per hole

30 10080 - Gopher II Hints: Use the function() Hints: do a transformation Hints: one Gopher = 1 unit of flow Hole The Constraint is 1 Gopher per hole

31 10080 - Gopher II Solution: Hole Source Sink 1 1 1 1 1 1

32 Let’s Try Want More?

33 563 - Crimewave 10 mins break. (Again, it is not actually a break. It is expected that you read the problem, and try to find the solution with your neighbor. ) http://uva.onlinejudge.org/index.php?option=c om_onlinejudge&Itemid=8&category=7&page =show_problem&problem=504

34 563 - Crimewave http://uva.onlinejudge.org/index.php?option=c om_onlinejudge&Itemid=8&category=7&page =show_problem&problem=504 Banks Get-away routes City Map Is it possible that no two get-away routes use the same crossing?

35 563 - Crimewave Hint: Use the function() A D E B C Only one route can pass through each node… But we can have constraints on edge only…

36 563 - Crimewave Hint: Use the function() A D E B C Only one route can pass through each node… Banks as Sources. City Bounds as Sink.

37 563 - Crimewave Hint: Use the function() A D E B C Is this okay? 1 1 1 1 1 1 1 1

38 563 - Crimewave Hint: Use the function() A1 D E B C Is this okay? A2 1

39 563 - Crimewave Hint: Use the function() A1 D E B C Is this okay? A2 1 A

40 Let’s Try Don’t worry. It is normal that you cannot get the solution right away. These problems are really difficult. That’s why we have to meet every week.

41 Review What processes were used when we solved the problem(s)? – Read and understand the problem – Transform the problem – Apply an “known” algorithm – Get back the solution

42 Review What processes were used when we solved the problem(s)? – Read and understand the problem – Transform the problem – Apply an “known” algorithm – Get back the solution – Code the problem – Way to represent the graph in the program (Data- Structure)

43 Review What processes were used when we solved the problem(s)? – Read and understand the problem – Transform the problem – Apply an “known” algorithm – Get back the solution – Code the problem – Way to represent the graph in the program (Data- Structure) Basically, we will cover most some of the topics here. But still, you need to practice on your own.

44 INPUT /OUTPUT Let’s get the hands dirty

45 483 - Word Scramble – http://uva.onlinejudge.org/index.php?option=co m_onlinejudge&Itemid=8&category=6&page=sho w_problem&problem=424 http://uva.onlinejudge.org/index.php?option=co m_onlinejudge&Itemid=8&category=6&page=sho w_problem&problem=424 This is a warm-up problem. You have to code this time. Start your notepad/ DEV C++/ vi/ gedit …

46 483 - Word Scramble Common way to read lines string line; while (getline(cin, line)){ //.. to process a line }

47 483 - Word Scramble ● For each line, we need to get the word (Token). istringstream ins(line); string word; while (ins >> word){ // reverse word }

48 483 - Word Scramble ● The last part is to reverse a word. ● You may instantly thinking about a loop to do this. ● Let’s try the STL reverse() function. for (size_t i = 0; i < words.size(); ++i) cout << words[words.size() - i - 1]; reverse(word.begin(), word.end()); cout << word;

49 reverse(…, …) What does the reverse(…, …) actually do? 1.Go to http://cplusplus.com/http://cplusplus.com/ 2.Search reverse.

50 reverse(…, …) void reverse ( BidirectionalIterator first, BidirectionalIterator last); HELLO First ( String.begin() ) Last ( String.end() )

51 reverse(…, …) HELLO First ( String.begin() ) Last ( String.end() ) Parameters first, last Bidirectional iterators to the initial and final positions of the sequence to be reversed. The range used is [first,last), which contains all the elements between first and last, including the element pointed by first but not the element pointed by last.

52 STL Standard Template Library Provides common library functions like reverse(…, …) More Example, 1.Go to http://cplusplus.com/http://cplusplus.com/ 2.See Reference  STL Algorithms

53 STL Standard Template Library Provides common container classes Hey, but, but what is container class?

54 STL Standard Template Library Array is an example of container, but it has limited functionality such as – The size is fixed – The index must be non-negative integer

55 STL Standard Template Library When I was a child, I always dreamt to have a non-fixed size array, now the dream comes true. It is called vector

56 Vector #include using namespace std; int main () { vector myvector (10); // 10 zero-initialized elements // assign some values: myvector[9] = 5; cout << myvector[9] << endl; myvector.push_back (15); myvector.push_back (16); cout << myvector[10] << “, “ << myvector[11] << endl; // 15, 16 }

57 STL Standard Template Library When I was a child, I also always dreamt to have an array that can use “string”, “char”, … as its index. – table[“denon”] = “smart”; – table[“david”] = “stupid”; Now the dream comes true again, it is called map

58 Map #include using namespace std; int main () { map table; first['a']=10; first['b']=30; first['c']=50; cout << table[‘a’] << “, “ << table[‘c’] << endl; //10, 50 return 0; }

59 STL More containers and algorithms will be covered in the following trainings For more information, – http://cplusplus.com/ http://cplusplus.com/ – http://www.sgi.com/tech/stl http://www.sgi.com/tech/stl

60 Exercises 642 - Word Amalgamation 401 - Palindromes 10107 - What is the Median?

61 ADMIN Here is the boring part…

62 Admin Website: http://www.cs.hku.hk/~provinci Mailing list: provinci@cs.hku.hkprovinci@cs.hku.hk Coach: Chan Ho Leung Email: hlchan@cs.hku.hk

63 Admin We’ll have a Mini Contest 1. test at Mar 11 (Thur) 18:30-21:00. ● To prepare for the Mini Contest 1, you can join our training sessions every Thursday in HW-311. – These training sessions are optional and you can join the contest directly.

64 Admin Tentative schedule http://i.cs.hku.hk/~provinci/training.html

65 PRACTICE MAKE PERFECT Finally…

66 Practice make perfect ● An archive of problems can be found in the site – http://acm.uva.es/p ● It also has an on-line judge to test your submitted program. – Simply register and apply for an account. ● This archive site will be a major source of training questions.

67 Practice make perfect ● Useful resources… http://ctldenon.net/resources.php Warm-up problems: 642 - Word Amalgamation 401 - Palindromes 10107 - What is the Median?

68 That’s All Thank you


Download ppt "Welcoming Lecture Meeting/Discussion/Party By David/Denon."

Similar presentations


Ads by Google