Skip to content

Commit

Permalink
Add 2023 solutions (#1)
Browse files Browse the repository at this point in the history
Merge pull request #1 from jfsscsclub/2023-Solutions
  • Loading branch information
justapotato213 authored Feb 22, 2023
1 parent 594e13e commit 53a45b2
Show file tree
Hide file tree
Showing 7 changed files with 132 additions and 0 deletions.
4 changes: 4 additions & 0 deletions 2016/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# CCC 2016
Note that these are only accessible if you are a student of the Peel District School Board and are logged into your school Google account. Otherwise, you will not have access.
## Slide Decks
- [S2](https://docs.google.com/presentation/d/1c3o4cSQfKFScKp3BfXM0b216HOMg3hURkNv4HBU2Ppc/)
4 changes: 4 additions & 0 deletions 2022/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# CCC 2022
Note that these are only accessible if you are a student of the Peel District School Board and are logged into your school Google account. Otherwise, you will not have access.
## Slide Decks
- [S2](https://docs.google.com/presentation/d/1c3o4cSQfKFScKp3BfXM0b216HOMg3hURkNv4HBU2Ppc/)
4 changes: 4 additions & 0 deletions 2023/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# CCC 2023
Note that these are only accessible if you are a student of the Peel District School Board and are logged into your school Google account. Otherwise, you will not have access.
## Slide Decks
- [S1/J4, S2, S3](https://docs.google.com/presentation/d/1ZOA_IlWxJPJdOiX4Cxhhy1WOK-nyPMLahiBfGsJwEmM/)
26 changes: 26 additions & 0 deletions 2023/s1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# CCC '23 J4/S1 - Aritro Saha
c = int(input())

# Gathering input, True represents a black triangle and False represents a white triangle
row1 = [bool(int(triangle)) for triangle in input().split()]
row2 = [bool(int(triangle)) for triangle in input().split()]

# The maximum tape that we need is the number of black triangles * the edges per triangle (3)
tape = (row1.count(True) + row2.count(True)) * 3

# Checking for left-right adjacency in both rows
for i in range(c - 1):
if row1[i] and row1[i + 1]:
tape -= 2 # Subtract 2 because one edge on both adjacent triangles aren't needed

if row2[i] and row2[i + 1]:
tape -= 2

# Checking for top-bottom adjacency
for i in range(c):
# If the triangles are pointing into each other, they don't share an edge
# Referring to the diagram, this only happens on even triangle columns (starting at 0)
if row1[i] and row2[i] and i % 2 == 0:
tape -= 2

print(tape)
19 changes: 19 additions & 0 deletions 2023/s2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# CCC '23 S2 - Roy Zhang
N = int(input())
hills = [int(i) for i in input().split(" ")]

# initialize grid
grid = []
for i in range(N):
grid.append([0] * N)

# solve
ans = [float('infinity')] * N
ans[0] = 0
for j in range(1, N):
for i in range(j - 1, -1, -1):
grid[i][j] = grid[i + 1][j - 1] + abs(hills[i] - hills[j])
if grid[i][j] < ans[j - i]:
ans[j - i] = grid[i][j]

print(" ".join(str(i) for i in ans))
74 changes: 74 additions & 0 deletions 2023/s3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# CCC '23 S3 - Roy Zhang
import math

NMRC = input().split(" ")
N, M, R, C = int(NMRC[0]), int(NMRC[1]), int(NMRC[2]), int(NMRC[3])

# initialize grid
grid = []
for i in range(N):
grid.append([0] * M)

# impossible case
if (R == N and C % 2 != 0 and M % 2 == 0) or (C == M and R % 2 != 0 and N % 2 == 0):
print("IMPOSSIBLE")
else:
# col palindromes
count = 0
if C % 2 == 1 and M % 2 == 1:
for i in range(N):
grid[i][M//2] = 'a'
C -= 1
count += 1

# col palindromes
for j in range(C):
for i in range(N):
if j % 2 == 0:
col_coord = math.ceil(j / 2)
else:
col_coord = M - math.ceil(j / 2)
grid[i][col_coord] = "a"

# row palindromes
for i in range(R):
if i == 0:
grid[i] = ['a'] * M
else:
for j in range(M):
if grid[i][j]: continue
if grid[i][M - j - 1]:
grid[i][j] = grid[i][M - j - 1]
else:
grid[i][j] = 'b'

# remaining cells
for i in range(N):
for j in range(M):
if grid[i][j]: continue
if i == 0:
grid[i][j] = 'f'
if not grid[i][M - j - 1]:
grid[i][M - j - 1] = 'g'
elif i % 2 == 0:
grid[i][j] = 'c'
if not grid[i][M - j - 1]:
grid[i][M - j - 1] = 'd'
else:
grid[i][j] = 'd'
if not grid[i][M - j - 1]:
grid[i][M - j - 1] = 'c'

# special cases
if C + count == M and R == 0:
for i in range(N):
grid[i][-1] = "e"

elif C + count == M and R != 0:
for i in range((N - R) // 2):
grid[i][0] = "e"
grid[N - i - 1][0] = 'e'

# print ans
for row in grid:
print("".join(str(i) for i in row))
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
A repository of CCC questions and solutions that were reviewed during John Fraser CS Club's lessons.

## Years
- [2023](/2023/)
- [2022](/2022/)
- [2021](/2021/)
- [2020](/2020/)
Expand Down

0 comments on commit 53a45b2

Please sign in to comment.