CSC108H5S Winter 2022, Assignment 2
Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit
CSC108H5S Winter 2022, Assignment 2
Q1: MCS Roast
Being tired of the challenging assignments given by the MCS Professors, students have collectively decided to have a roasting contest with the professors. We divide participants into two teams: students and professors. Each participant gets 500 points for their team when they roast a participant from the opposing team. Moreover, if the same participant roasts someone from the opposing team again within 10 minutes, their team gets an additional 500 points.
For example, if a participant roasts twice within 10 minutes, their team gets 500+500 = 1000 points.
As another example, if a participant roasts for the first time, roasts for the second time within 10 minutes, and then roasts within 10 minutes of their second roast, their team gets 500 + (500 + 500) + (500 + 500) = 2500 points.
Filename
Your filename for this question must be q1.py.
Input
The first line contains the integer n (1 <= n <= 200), the number of times participants roasted each other in the contest.
The second line contains the integer m1 denoting the total number of students.
The third line contains the integer m2 denoting the total number of professors.
Each of the following n lines contains one of the following:
t_i sj pk
t_i pk sj
In the lines above, 0 <= t_i <= 120, 1 <= j <= m1, 1 <= k <= m2 denoting student sj, professor pk, and time t_i (in minutes). Note here that while j and k are integers, s and p are characters denoting “student” and “professor” respectively. The line t_i sj pk denotes that student j roasted professor k at time t_i, while t_i pk sj denotes that professor k roasted student j at time t_i.
The numbers t_i are distinct and are in increasing order.
Output
One line with the total score of team students, a space, and the total score of team professors.
Sample Input 1
3
3
3
1 s1 p2
2 s1 p1
3 p1 s2
Sample Output 1
1500 500
Sample Input 2
4
4
5
1 s1 p1
3 p1 s2
4 s2 p2
5 p4 s1
Sample Output 2
1000 1000
Sample Input 3
6
4
5
1 s1 p1
3 p1 s2
4 s2 p2
5 p4 s1
6 p4 s2
7 s2 p4
Sample Output 3
2000 2000
Q2: Kiki’s Cards
Kiki is making “Happy National Pizza Day” (February 9th) cards for all of her friends. She’s a bit disappointed with the cards not looking special enough, so she decides to add glitter to them to make them look more special. However, she’s short on glitter, so she decides to add glitter selectively.
She uses a box with N * N divided sections to store her cards. Each section is huge and each card is small, so she can put multiple cards in a given section and they will never overlap. We model the way that she organizes the cards and adds glitter using two commands:
Command 1: 1 x y: add a card to the box in section (x, y).
Command 2: 2 x1 y1 x2 y2: Add one unit of glitter to each of the cards in the sections from (x1, y1) to (x2, y2).
Help Kiki determine the total number of units of glitter that she placed on the cards.
Filename
Your filename for this question must be q2.py.
Input
The first line will contain N (1 <= N <= 500) and C (1 <= C <= 500 ), the square size of the card storage box and the number of commands.
The next C lines will contain one of the commands listed above.
Command 1 will contain x (1 <= x <= N) and y (1 <= y <= N), the coordinates where a new card will be added.
Command 2 will contain x1, y1, x2, and y2 (1 <= x1 <= x2 <= N, 1 <= y1 <= y2 <= N), a rectangle of sections where one unit of glitter is added to all the cards.
Output
Output the total number of units of glitter placed on the cards.
Sample Input 1
5 6
1 2 3
1 5 5
2 2 3 5 5
1 3 3
2 2 3 3 3
2 2 3 5 5
Sample Output 1
7
Sample Input 2
4 4
1 3 2
1 4 3
2 1 1 2 4
2 1 1 4 2
Sample Output 2
1
Q3: Cool Chemicals
In an alternate reality, chemistry Professors Hodge and Sibia have teamed up to design a chemical compound X such that when X is added to Dan’s favorite food (saltine crackers), it’ll make him despise it. For this, they are working with 6 kinds of extracts:
Singleton Extracts: berries (B), green veggies (G), dairy (D)
Combination Extracts: icecream (I), salad (S), and cheese sauce (C).
Like regular food, mixing two extracts of the same kind will result in an extract of the same kind (eg. mixing berries B with berries B will result in berries B).
Mixing two singleton extracts will result in a combination extract, using these rules:
Berries (B) + Green Veggies (G) = Salad (S)
Berries (B) + Dairy (D) = Icecream (I)
Green Veggies (G) + Dairy (D)= Cheese Sauce (C)
Mixing two combination extracts will result in a singleton extract closest to them. For example, Icecream (I) + Salad (S) is closest to Berries (B) since both Icecream and Salad extracts require using Berry extracts according to the rules above.
Mixing any singleton extract with a combination extract will result in a Tasteless (T) extract. Combining the Tasteless extract with any extract will result in that extract. For example: Tasteless (T) + Salad (S) will result in Salad (S).
In the lab of cool chemicals, extracts are organized into an upside-down triangle, with each row containing one fewer extract than the row above. The top row has a capital letter in each cell representing the first letter of the extract stored there. Each of the cell extracts in the next row is found by mixing the extracts in the two cells above. For example, the first cell is the result of mixing the first two cells from the row above, the second cell is the result of mixing the second and third cells from the row above, and so on. This process continues until the bottom row. Given a string of letters for the top row, output the first letter of the extract in the bottom cell as an uppercase letter.
Filename
Your filename for this question must be q3.py.
Input
The first (and only) line will contain characters representing the extracts in the top row. (note: these can only be: B, G, D, I, S, and C).
Output
A single capital letter representing the extract in the bottom cell (B, G, D, I, S, C, or T).
Sample Input 1
CBGCCSD
Sample Output 1
T
Sample Output 1 Explanation
The input row we get is CBGCCSD. To generate the next row, we mix each pair of neighbouring extracts in row 1. So our next row will be: TSTCGT (C+B, B+G, G+C, C+C, C+S, S+D). The third row will be: SSCTG (T+S, S+T, T+C, C+G, G+T). The fourth row will be: SGCG (S+S, S+C, C+T, T+G). The fifth row will be: TTT (S+G, G+C, C+G). The sixth row will be: TT. And our final row will be: T.
Sample Input 2
GDGDDDDGSB
Sample Output 2
D
Sample Input 3
CBGCCSS
Sample Output 3
C
Reminders
You are not allowed to add any import statements.
Test, test, test! The sample inputs/outputs that we give you in the assignment handout are not to be considered full testing.
Please submit all of your files to MarkUs.
Prior to submitting your files, it’s in your best interest to try some other practice problems on DMOJ to get used to how to write and submit code. On DMOJ you paste your code, whereas on MarkUs you upload it, but the idea is otherwise similar.
You must work alone on this assignment.
The final thing you should do is to open your code files in Notepad and make sure that the code displays correctly as only Python code.
2022-02-08