From: Skullheadx <704277@pdsb.net> Date: Thu, 6 Oct 2022 03:21:27 +0000 (-0400) Subject: S3 2018 X-Git-Url: http://git.skullheadx.com/tech/index.html?a=commitdiff_plain;h=faa66f4ce169d9cca588d414b67e847e32b21fce;p=CCC.git S3 2018 --- diff --git a/Main/C++/2018/S3.cpp b/Main/C++/2018/S3.cpp new file mode 100644 index 0000000..9712f6a --- /dev/null +++ b/Main/C++/2018/S3.cpp @@ -0,0 +1,8 @@ +#include +using namespace std; + +int main() +{ + + return 0; +} diff --git a/Main/Python/2018/S3.py b/Main/Python/2018/S3.py new file mode 100644 index 0000000..0596994 --- /dev/null +++ b/Main/Python/2018/S3.py @@ -0,0 +1,130 @@ +from queue import Queue + +N, M = tuple(map(int, input().split())) + +maze = [] + +for i in range(N): + maze.append(list(input())) +targets = dict() +for y, row in enumerate(maze): + for x, val in enumerate(row): + if val == "S": + starting_pos = (x, y) + maze[y][x] = '.' + elif val == ".": + targets[(x, y)] = -1 +# Check Cameras +temp = [row[:] for row in maze] +for y, row in enumerate(temp): + for x, val in enumerate(row): + if val == "C": + # check up + for i in range(y+1, N): + if temp[i][x] == ".": + maze[i][x] = "W" + elif temp[i][x] == "W" or temp[i][x] == "C": + break + for i in range(y-1, -1, -1): + if temp[i][x] == ".": + maze[i][x] = "W" + elif temp[i][x] == "W" or temp[i][x] == "C": + break + for i in range(x+1, M): + if temp[y][i] == ".": + maze[y][i] = "W" + elif temp[y][i] == "W" or temp[y][i] == "C": + break + for i in range(x-1, -1, -1): + if temp[y][i] == ".": + maze[y][i] = "W" + elif temp[y][i] == "W" or temp[y][i] == "C": + break + maze[y][x] = 'W' + +# Check Conveyors +for y, row in enumerate(maze): + for x, val in enumerate(row): + if val == "L": + if maze[y][x - 1] in ("R", "W"): + maze[y][x] = "W" + elif val == "R": + if maze[y][x + 1] in ("L", "W"): + maze[y][x] = "W" + elif val == "U": + if maze[y - 1][x] in ("D", "W"): + maze[y][x] = "W" + elif val == "D": + if maze[y + 1][x] in ("U", "W"): + maze[y][x] = "W" + +# for i in maze: +# print(*i) + +if maze[starting_pos[1]][starting_pos[0]] == 'W': + for i in targets.values(): + print(i) + quit() + +seen = set() +q = Queue() +q.put(starting_pos) +q.put("|") + +movement = { + "U": (0, -1), + "D": (0, 1), + "L": (-1, 0), + "R": (1, 0) +} + +steps = 0 + +while not q.empty(): + current = q.get() + + if current == "|": + steps += 1 + if not q.empty(): + q.put("|") + continue + + if current in seen: + continue + else: + seen.add(current) + + x, y = current + + while maze[y][x] in movement.keys(): + t_x = x + t_x += movement[maze[y][x]][0] + y += movement[maze[y][x]][1] + x = t_x + + if (x,y) in targets: + if targets[(x,y)] == -1: + targets[(x,y)] = steps + + + + + if maze[y - 1][x] == '.': + q.put((x, y - 1)) + elif maze[y - 1][x] in (movement.keys()): + q.put((x + movement[maze[y - 1][x]][0], y - 1 + movement[maze[y - 1][x]][1])) + if maze[y + 1][x] == '.': + q.put((x, y + 1)) + elif maze[y + 1][x] in (movement.keys()): + q.put((x + movement[maze[y + 1][x]][0], y + 1 + movement[maze[y + 1][x]][1])) + if maze[y][x - 1] == '.': + q.put((x - 1, y)) + elif maze[y][x - 1] in (movement.keys()): + q.put((x - 1 + movement[maze[y][x - 1]][0], y + movement[maze[y][x - 1]][1])) + if maze[y][x + 1] == '.': + q.put((x + 1, y)) + elif maze[y][x + 1] in (movement.keys()): + q.put((x + 1 + movement[maze[y][x + 1]][0], y + movement[maze[y][x + 1]][1])) + +for i in targets.values(): + print(i) diff --git a/Main/test.py b/Main/test.py new file mode 100644 index 0000000..95b58d3 --- /dev/null +++ b/Main/test.py @@ -0,0 +1,18 @@ +test = {"A":'a', "B":'b'} + +if "A" in test: + print("1") + +if "a" in test: + print("2") + +test['C'] = 'c' + +test[(0,0)] = 'd' + +print(test) + +test["A"] = 'L' + +for i in test.values(): + print(i)