Aflv 01 Introduction
Aflv 01 Introduction
Aflv 01 Introduction
Welcome
Goal
solve it efficiently
by using algorithms and data structures,
convert our solution into a program,
do it as quickly as possible (under pressure)
and do it correctly (without bugs)
How?
Course book
Piazza
Course schedule
6
7
8
9
10
11
12
13
Date
01.12
02.12
03.12
04.12
05.12
06.12
07.12
08.12
09.12
10.12
11.12
12.12
13.12
14.12
15.12
16.12
17.12
18.12
19.12
Topics
Introduction
Data structures and libraries
Data structures
Problem solving paradigms
Greedy algorithms
Dynamic programming
Activities
Problem session I
Hand in problem sets from week 1
Dynamic programming
Unweighted graphs
Graphs
Network flow
Mathematics
Problem session II
Hand in problem sets from week 2
Strings
Geometry
Final exam
Hand in problem sets from week 3
Hand in bonus problems
Problem sets
Problem sets
Bonus problems
10
11
Problem sessions
12
Final exam
13
Course evaluation
Problem sets
Problem sessions
Final exam
Bonus problems
Total
70%
10%
20%
20%
120%
14
Introduction
The problems
Problem description
Input description
Output description
Example input/output
A time limit in seconds
A memory limit in bytes
16
Example problem
Problem description
For each test case, output one line containing the value of
A B.
17
Example problem
Sample input
Sample output
4
3 4
13 0
1 8
100 100
12
0
8
10000
18
Example solution
#include <iostream>
using namespace std;
int main() {
int T;
cin >> T;
for (int t = 0; t < T; t++) {
int A, B;
cin >> A >> B;
cout << A * B << endl;
}
return 0;
}
19
Example solution
#include <iostream>
using namespace std;
int main() {
int T;
cin >> T;
for (int t = 0; t < T; t++) {
int A, B;
cin >> A >> B;
cout << A * B << endl;
}
return 0;
}
19
Example solution
#include <iostream>
using namespace std;
int main() {
int T;
cin >> T;
for (int t = 0; t < T; t++) {
int A, B;
cin >> A >> B;
cout << A * B << endl;
}
return 0;
}
Example solution
#include <iostream>
using namespace std;
int main() {
int T;
cin >> T;
for (int t = 0; t < T; t++) {
int A, B;
cin >> A >> B;
cout << A * B << endl;
}
return 0;
}
Example solution
#include <iostream>
using namespace std;
int main() {
int T;
cin >> T;
for (int t = 0; t < T; t++) {
int A, B;
cin >> A >> B;
cout << A * B << endl;
}
return 0;
}
Example solution
20
Example solution
20
Example solution
20
Example solution
#include <iostream>
using namespace std;
int main() {
int T;
cin >> T;
for (int t = 0; t < T; t++) {
long long A, B;
cin >> A >> B;
cout << A * B << endl;
}
return 0;
}
21
Example solution
#include <iostream>
using namespace std;
int main() {
int T;
cin >> T;
for (int t = 0; t < T; t++) {
long long A, B;
cin >> A >> B;
cout << A * B << endl;
}
return 0;
}
21
Example solution
#include <iostream>
using namespace std;
int main() {
int T;
cin >> T;
for (int t = 0; t < T; t++) {
long long A, B;
cin >> A >> B;
cout << A * B << endl;
}
return 0;
}
21
Automatic judging
C
C++
Java
Python 2
Python 3
C#
and others
22
Judge verdicts
Accepted
Wrong Answer
Compile Error
Run Time Error
Time Limit Exceeded
Memory Limit Exceeded
23
Tips
24
25
Sub-Category
Straightforward
Simulation
Iterative
Backtracking
Classic
Original
Classic
Original
Frequency
1-2
0-1
0-1
0-1
0-1
0
1
0
1-3
1-2
1-2
1
1
0-1
26
27
28
n
10
15
20
50
102
103
105
106
Example
Enumerating a permutation
DP TSP
DP + bitmask technique
DP with 3 dimensions + O(n) loop, choosing n Ck = 4
Floyd Warshalls
Bubble/Selection/Insertion sort
Merge sort, building a Segment tree
Usually, contest problems have n 106 (to read input)
29
30
31
32
Ad Hoc problems
Ad Hoc problems
34
35
The first line of input is an integer T (T < 20) that indicates the
number of test cases. Each case consists of a line with 3
distinct positive integers. These 3 integers represent the
salaries of the three employees. All these integers will be in the
range [1000, 10000].
Output
For each case, output the case number followed by the salary
of the person who survives.
36
Sample output
3
1000 2000 3000
3000 2500 1500
1500 1200 1800
Case 1: 2000
Case 2: 2500
Case 3: 1500
37
39
ghi
pqrs
abc
jkl
tuv
<SP>
def
mno
wxyz
In the above grid each cell represents one key. Here <SP>
means a space. In order to type the letter a, we must press
that key once, however to type b the same key must be
repeatedly pressed twice and for c three times. In the same
manner, one key press for d, two for e and three for f. This is
also applicable for the remaining keys and letters. Note that it
takes a single press to type a space.
40
For every case of input there will be one line of output. It will
first contain the case number followed by the number of key
presses required to type the message of that case. Look at the
sample output for exact formatting.
41
Sample output
2
welcome to ulab
good luck and have fun
Case #1: 29
Case #2: 41
42
44
Problem set 1
45