Skip to content

Commit

Permalink
Update as of 15 May 2024
Browse files Browse the repository at this point in the history
  • Loading branch information
RussellDash332 committed May 15, 2024
1 parent e367968 commit a1ed3bf
Show file tree
Hide file tree
Showing 9 changed files with 719 additions and 316 deletions.
328 changes: 170 additions & 158 deletions README.md

Large diffs are not rendered by default.

532 changes: 374 additions & 158 deletions docs/index.html

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions src/A Flea on a Chessboard/fleaonachessboard.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import sys; input = sys.stdin.readline
while True:
S, x, y, dx, dy = map(int, input().split()); t = 0
if S < 1: break
while True:
m = x%(2*S); n = y%(2*S)
if (S<m<2*S and 0<n<S) or (S<n<2*S and 0<m<S): break
t += 1; x += dx; y += dy
if t == 10000: break
if t < 10000: print(f'After {t} jumps the flea lands at ({x}, {y}).')
else: print('The flea cannot escape from black squares.')
16 changes: 16 additions & 0 deletions src/Beehives (2)/beehives2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import sys; input = sys.stdin.readline
V, E = map(int, input().split()); G = [set() for _ in range(V)]; M = 10**9
for _ in range(E): a, b = map(int, input().split()); G[a].add(b); G[b].add(a)
for i in range(V):
for j in G[i]:
for k in G[j]:
if i in G[k]: print(3); exit(0)
for i in range(V):
S = [0]*V; Q = [(i, -1, 1)]
for u, p, d in Q:
if d >= M: break
if S[u]: M = min(M, d+S[u]-2); break
S[u] = d
for v in G[u]:
if v != p: Q.append((v, u, d+1))
print(M if M < 10**9 else 'impossible')
6 changes: 6 additions & 0 deletions src/Booking/booking.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import sys; input = sys.stdin.readline; from datetime import *
for _ in range(int(input())):
B, C = map(int, input().split()); Q = []; a = c = 0
for _ in range(B): _, sd, st, ed, et = input().split(); s = datetime.strptime(sd+' '+st, '%Y-%m-%d %H:%M'); e = datetime.strptime(ed+' '+et, '%Y-%m-%d %H:%M')+timedelta(minutes=C); Q.append((s, 1)); Q.append((e, -1))
for x, v in sorted(Q): c += v; a = max(a, c)
print(a)
95 changes: 95 additions & 0 deletions src/Distributing Seats/distributingseats.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
class Vertex:
def __init__(self, v, count=1):
self.key, self.left, self.right, self.parent = v, None, None, None
self.height, self.size, self.count = 0, 1, count

class AVL:
def __init__(self):
self.root = None
def search(self, v):
res = self.helper_search(self.root, v)
return res.key if res != None else -10
def helper_search(self, t, v):
if t == None: return None
elif t.key == v: return t
elif t.key < v: return self.helper_search(t.right, v)
return self.helper_search(t.left, v)
def find_min(self):
return self.helper_find_min(self.root)
def helper_find_min(self, t):
if t == None: return -10
if t.left == None: return t.key
return self.helper_find_min(t.left)
def successor(self, v):
self.insert(v); k = self.helper_successor_plus(self.helper_search(self.root, v)); self.delete(v); return k
def helper_successor_plus(self, t):
if t.right != None: return self.helper_find_min(t.right)
else:
par, cur = t.parent, t
while par != None and cur == par.right: cur, par = par, par.parent
if par == None: return -10
else: return par.key
def update_height(self, t):
if t.left != None and t.right != None: t.height = max(t.left.height, t.right.height) + 1
elif t.left != None: t.height = t.left.height + 1
elif t.right != None: t.height = t.right.height + 1
else: t.height = 1
def update_size(self, t):
if t.left != None and t.right != None: t.size = t.left.size + t.right.size + t.count
elif t.left != None: t.size = t.left.size + t.count
elif t.right != None: t.size = t.right.size + t.count
else: t.size = t.count
def balance_factor(self, t):
if t.left != None and t.right != None: return t.left.height - t.right.height
elif t.left != None: return t.left.height + 1
elif t.right != None: return -1 - t.right.height
return 0
def insert(self, v, count=1):
def helper(t, v):
if t == None: return Vertex(v, count)
if t.key < v: t.right = helper(t.right, v); t.right.parent = t
elif t.key > v: t.left = helper(t.left, v); t.left.parent = t
else: t.count += count
self.update_height(t), self.update_size(t); t = self.rebalance(t); return t
self.root = helper(self.root, v)
def delete(self, v):
def helper(t, v):
if t == None: return t
if t.key < v: t.right = helper(t.right, v)
elif t.key > v: t.left = helper(t.left, v)
else:
if t.count == 1:
if t.left == None and t.right == None: t = None
elif t.left == None and t.right != None: t.right.parent = t.parent; t = t.right
elif t.left != None and t.right == None: t.left.parent = t.parent; t = t.left
else:
successor_v = self.successor(v); t.key = successor_v; t.right = helper(t.right, successor_v)
else: t.count -= 1
if t != None: self.update_height(t), self.update_size(t); t = self.rebalance(t)
return t
self.root = helper(self.root, v)
def rebalance(self, t):
if t == None: return t
if self.balance_factor(t) == 2:
if self.balance_factor(t.left) == -1: t.left = self.left_rotate(t.left)
t = self.right_rotate(t)
elif self.balance_factor(t) == -2:
if self.balance_factor(t.right) == 1: t.right = self.right_rotate(t.right)
t = self.left_rotate(t)
return t
def left_rotate(self, t):
w = t.right; w.parent = t.parent; t.parent = w; t.right = w.left
if w.left != None: w.left.parent = t
w.left = t; self.update_height(t), self.update_size(t), self.update_height(w), self.update_size(w); return w
def right_rotate(self, t):
w = t.left; w.parent = t.parent; t.parent = w; t.left = w.right
if w.right != None: w.right.parent = t
w.right = t; self.update_height(t), self.update_size(t), self.update_height(w), self.update_size(w); return w

import sys; input = sys.stdin.readline; from array import *
avl = AVL(); n, r, c = map(int, input().split()); A = array('i', [0]*r); Q = []
for _ in range(n): a, _, s = map(int, input().split()); Q.append((max(min(a-1+s, r-1), 0), max(min(a-1-s, r-1), 0)))
for i in range(r): avl.insert(i, c)
for y, x in sorted(Q):
if avl.search(z:=x) == x or -1 < (z:=avl.successor(x)) <= y: A[z] += 1; avl.delete(z)
print(sum(A))
1 change: 1 addition & 0 deletions src/Government Help/help.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
while(n:=int(input())):a=sorted(map(int,input().split()));print(*[f'{a[-i]}-{"AB"[i%2]}'for i in range(n)])
9 changes: 9 additions & 0 deletions src/Toy Train Tracks/toytraintracks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
s, c = map(int, input().split()); s -= s%2; c -= c%2
if s == 0:
c -= c%4
if c <= 8: print('LLLL')
elif c <= 12: print('LRRLRRLRRLRR')
else: print(('RLRRLR'+'LR'*((c-12)//4))*2)
else:
if c%4 == 0: print(('L'+'S'*(s//2)+'L'+'RL'*((c-4)//4))*2)
else: print('LR'*((c-6)//4)+'L'+'S'*(s//2)+'LL'+'S'*(s//2-1)+'R'+'LR'*((c-6)//4)+'LLS')
37 changes: 37 additions & 0 deletions src/Worst Weather Ever/worstweather.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# https://stackoverflow.com/questions/31106459/how-to-adapt-fenwick-tree-to-answer-range-minimum-queries/34602284#34602284
def update(a, i, x):
a[i] = x
while i > 1:
i //= 2; a[i] = a[2*i]
if a[2*i+1] > a[2*i]: a[i] = a[2*i+1]
def rmq(a, i, j):
x = -INF
while i < j:
if i%2 == 0: i //= 2
else:
if a[i] > x: x = a[i]
i = i//2+1
if j%2 == 0: j //= 2
else:
if a[j-1] > x: x = a[j-1]
j //= 2
return x

import sys, os, io; input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline; print = sys.stdout.write; from bisect import *; INF = 10**9+1
while (n:=int(input())):
R = {}
for _ in range(n): y, r = map(int, input().split()); R[y] = r
A = sorted(R); F = [0]*2*n
for i in range(n): update(F, i+n, R[A[i]])
for _ in range(int(input())):
y, x = map(int, input().split()); nxt = bisect_left(A, y+1); prv = bisect_left(A, x)-1
if x not in R:
if y in R and rmq(F, nxt+n, prv+n+1) >= R[y]: print('false\n')
else: print('maybe\n')
elif rmq(F, nxt+n, prv+n+1) >= R[x]: print('false\n')
elif y in R:
if R[y] < R[x]: print('false\n')
elif prv-nxt == x-y-2: print('true\n')
else: print('maybe\n')
else: print('maybe\n')
input(); print('\n')

0 comments on commit a1ed3bf

Please sign in to comment.