Aflv 01 Introduction PDF
Aflv 01 Introduction PDF
Aflv 01 Introduction PDF
2
Goal
3
How?
4
Course book
5
Piazza
6
Course schedule
7
Problem sets
8
Problem sets
9
Bonus problems
10
Late handins, partial grading
11
Problem sessions
12
Final exam
13
Course evaluation
14
Introduction
The problems
16
Example problem
Problem description
Write a program that multiplies pairs of integers.
Input description
Input starts with one line containing an integer T , where 1 ≤ T ≤ 100,
denoting the number of test cases. Then T lines follow, each containing
a test case. Each test case consists of two integers A, B, where −220 ≤
A, B ≤ 220 , separated by a single space.
Output description
For each test case, output one line containing the value of A × B.
17
Example problem
4
12
3 4
0
13 0
8
1 8
10000
100 100
18
Example solution
#include <iostream>
using namespace std;
int main() {
int T;
cin >> T;
int A, B;
cin >> A >> B;
return 0;
}
19
Example solution
#include <iostream>
using namespace std;
int main() {
int T;
cin >> T;
int A, B;
cin >> A >> B;
return 0;
}
19
Example solution
#include <iostream>
using namespace std;
int main() {
int T;
cin >> T;
int A, B;
cin >> A >> B;
return 0;
}
19
Example solution
#include <iostream>
using namespace std;
int main() {
int T;
cin >> T;
int A, B;
cin >> A >> B;
return 0;
}
19
Example solution
#include <iostream>
using namespace std;
int main() {
int T;
cin >> T;
int A, B;
cin >> A >> B;
return 0;
}
19
Example solution
20
Example solution
20
Example solution
20
Example solution
#include <iostream>
using namespace std;
int main() {
int T;
cin >> T;
long long A, B;
cin >> A >> B;
return 0;
}
21
Example solution
#include <iostream>
using namespace std;
int main() {
int T;
cin >> T;
long long A, B;
cin >> A >> B;
return 0;
}
21
Example solution
#include <iostream>
using namespace std;
int main() {
int T;
cin >> T;
long long A, B;
cin >> A >> B;
return 0;
}
21
Automatic judging
22
Judge verdicts
23
Tips
• There are a couple of tips and guidelines you can keep in mind
towards becoming a more effective programmer and better problem
solver
24
Tip 0: Faster typing
25
Tip 1: Quickly classify problems
26
Tip 2: Do Algorithm Analysis
• When solving a problem, our solution has to be fast enough and can
not use too much memory
• We also want our solution to be as simple as possible
27
Tip 2: Do Algorithm Analysis
• When solving a problem, our solution has to be fast enough and can
not use too much memory
• We also want our solution to be as simple as possible
27
Tip 2: Do Algorithm Analysis
• When solving a problem, our solution has to be fast enough and can
not use too much memory
• We also want our solution to be as simple as possible
27
Tip 2: Do Algorithm Analysis
• When solving a problem, our solution has to be fast enough and can
not use too much memory
• We also want our solution to be as simple as possible
• Always go for the simplest solution that will pass the time limit
27
Tip 2: Do Algorithm Analysis
28
Tip 2: Do Algorithm Analysis
29
Tip 3: Master Programming Languages
• You should know your programming language like the back of your
hand
• This includes your programming language’s library
• C++’s Standard Template Library
• The Java Class Library
• If it’s already implemented in the standard library, you usually don’t
need to implement it yourself
30
Tip 4: Test your solution
• You want to make sure your solution is correct and runs within the
time limit
• Or you already know it’s wrong, but don’t know why
31
Tip 5: Practice and more practice
32
Ad Hoc Problems
Ad Hoc problems
34
Problem: Cost Cutting
Company XYZ have been badly hit by recession and is taking a lot of cost
cutting measures. Some of these measures include giving up office space, going
open source, reducing incentives, cutting on luxuries and issuing pink slips.
They have got three (3) employees working in the accounts department and are
going to lay-off two (2) of them. After a series of meetings, they have decided
to dislodge the person who gets the most salary and the one who gets the
least. This is usually the general trend during crisis like this. You will be given
the salaries of these 3 employees working in the accounts department. You
have to find out the salary of the person who survives.
35
Problem: Cost Cutting
Input
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
Problem: Cost Cutting
3
Case 1: 2000
1000 2000 3000
Case 2: 2500
3000 2500 1500
Case 3: 1500
1500 1200 1800
37
Cost Cutting: Solution
#include <cstdio>
#include <algorithm>
using namespace std;
int main() {
int T;
scanf("%d", &T);
int salary[3];
scanf("%d", &salary[0]);
scanf("%d", &salary[1]);
scanf("%d", &salary[2]);
return 0;
}
38
Problem: SMS Typing
39
Problem: SMS Typing
In this problem we will assume that the key pad of our cell phone is arranged as
follows.
abc def
ghi jkl mno
pqrs tuv wxyz
<SP>
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
Problem: SMS Typing
Input
The first line of input will be a positive integer T where T denotes the number
of test cases. T lines will then follow each containing only spaces and lower case
letters. Each line will contain at least 1 and at most 100 characters.
Output
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
Problem: SMS Typing
2
Case #1: 29
welcome to ulab
Case #2: 41
good luck and have fun
42
SMS Typing: Solution
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;
string keys[12] = {
"", "abc", "def",
"ghi", "jkl", "mno",
"pqrs", "tuv", "wxyz",
"", " ", ""
};
int main() {
int T;
scanf("%d\n", &T);
return 0;
}
43
SMS Typing: Solution
string line;
getline(cin, line);
int cnt = 0;
for (int i = 0; i < line.size(); i++) {
int cur;
for (int j = 0; j < 12; j++) {
for (int k = 0; k < keys[j].size(); k++) {
if (line[i] == keys[j][k]) {
cur = k + 1;
}
}
}
cnt += cur;
}
44
Problem set 1
45