TORONTO KIDS COMPUTER CLUB | Aurora Saturday 14:30 Python Practice 21.02.27.
19118
post-template-default,single,single-post,postid-19118,single-format-standard,ajax_fade,page_not_loaded,,qode-theme-ver-7.6.2,wpb-js-composer js-comp-ver-6.8.0,vc_responsive

Aurora Saturday 14:30 Python Practice 21.02.27.

03 Mar Aurora Saturday 14:30 Python Practice 21.02.27.

Question:
A new and upcoming artist has a unique way to create checkered patterns. The idea is to use an M-by-N canvas which is initially entirely black. Then the artist repeatedly chooses a row or column and runs their magic brush along the row or column. The brush changes the colour of each cell in the row or column from black to gold or gold to black.

Given the artist’s choices, your job is to determine how much gold appears in the pattern determined by these choices.

Input Specification
The first line of input will be a positive integer M. The second line of input will be a positive integer N. The third line of input will be a positive integer K. The remaining input will be K lines giving the choices made by the artist. Each of these lines will either be R followed by a single space and then an integer which is a row number, or C followed by a single space and then an integer which is a column number. Rows are numbered top down from 1 to M. Columns are numbered left to right from 1 to N.

Output Specification
Output one non-negative integer which is equal to the number of cells that are gold in the pattern determined by the artist’s choices.

Sample Input 1
3
3
2
R 1
C 1

Output for Sample Input 1
4

Explanation of Output for Sample Input 1
After running the brush along the first row, 
the canvas looks like this:
GGG
BBB
BBB
Then after running the brush along the first column, 
four cells are gold in the final pattern determined by the artist’s choices:
BGG
GBB
GBB

Sample Input 2
4
5
7
R 3
C 1
C 2
R 2
R 2
C 1
R 4

Output for Sample Input 2
10

Explanation of Output for Sample Input 2
Ten cells are gold in the final pattern determined by the artist’s choices:
BGBBB
BGBBB
GBGGG
GBGGG

Hint:
Remember the following hint we gave in the class:
m = int(input())
n = int(input())
k = int(input())

r1 = n
c1 = m

r_set = set() #if row not exist, add into set, c1- c2+
#else, remove from set, c1+ c2-
c_set = set()

# counts number in r_set and multiply it by r1
No Comments

Sorry, the comment form is closed at this time.