Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Bitnami MediaWiki
Search
Search
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
1642 - Culegere
(section)
Page
Discussion
English
Read
Edit
Edit source
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
Edit source
View history
General
What links here
Related changes
Special pages
Page information
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
= Exemplul 1 = <code>culegere.in</code> 4 5 3 4 1 1 5 1 5 2 1 1 2 6 3 2 2 1 2 5 2 2 4 4 3 5 4 <code>culegere.out</code> LIBER O.... OO#.. ..... ..... === Explicație === '''Secunda 0:''' OO#.. ..... ..... ..... '''Secunda 1:''' apare 1 măr, deplasare spre Est .OO#M ..... ..... ..... '''Secunda 2:''' apar <code>2</code> schimbătoare, deplasare spre Est, înghite măr, creşte coada 3OOO# 2.... ..... ..... '''Secunda 3:''' apare un schimbător pe <code>(4, 4)</code>, deplasare spre Est şi capul apare pe prima coloană peste schimbătorul <code>3</code> din poziţia <code>(1, 1)</code> #.OOO 2.... ..... ....4 '''Secunda 4:''' Nu apar şi nu dispar obiecte, deplasare spre Sud, corpul urmează acelaşi traseu ca şi capul care a fost influenţat la secunda <code>3</code> de schimbătorul cu valoarea <code>3</code>; capul ajunge peste schimbătorul <code>2</code> de la poziţia <code>(2,1)</code> O..OO #.... ..... ....4 '''Secunda 5:''' dispare schimbătorul de la <code>(4, 4)</code>, deplasare spre Est deoarece capul a fost influenţat de schimbătorul cu valoarea <code>2</code> la secunda <code>4</code>; dacă mărul nu ar fi fost mâncat, acum ar fi dispărut O...O O#... ..... ..... '''Secunda 6:''' dispare primul schimbător chiar dacă acesta a fost acoperit de corpul lui Snake, deplasare spre Est O.... OO#.. ..... ..... Aceasta este configuraţia finală deoarece acum a dispărut şi ultimul obiect. Snake nu s-a blocat în propriul corp, deci este LIBER.<syntaxhighlight lang="python" line="1"> from collections import deque # Citire date de intrare N, M = map(int, input().split()) K = int(input()) E = int(input()) events = [] for _ in range(E): st, x, y, t, en = input().split() st, x, y, en = int(st), int(x), int(y), int(en) if t.isdigit(): t = int(t) events.append((st, x-1, y-1, t, en)) # Direcții: Nord (1), Est (2), Sud (3), Vest (4) directions = [(0, 1), (1, 0), (0, -1), (-1, 0)] # E, S, W, N # Inițializare șarpe snake = deque([(0, i) for i in range(K)]) head = (0, K-1) direction = 0 # Inițial est (E) occupied = set(snake) # Evenimente active active_apples = {} active_switchers = {} # Stare șarpe snake_alive = True time = 0 def move_snake(): global head, direction new_head = ((head[0] + directions[direction][0]) % N, (head[1] + directions[direction][1]) % M) if new_head in occupied: return False occupied.add(new_head) snake.append(new_head) if new_head in active_apples: occupied.add(snake[-1]) active_apples.pop(new_head) else: tail = snake.popleft() occupied.remove(tail) head = new_head if new_head in active_switchers: direction = active_switchers[new_head] return True # Simulare while snake_alive and events: # Elimina evenimentele care expira la timpul actual for pos in list(active_apples.keys()): if active_apples[pos] == time: active_apples.pop(pos) for pos in list(active_switchers.keys()): if active_switchers[pos][1] == time: active_switchers.pop(pos) # Adaugă evenimente noi while events and events[0][0] == time: st, x, y, t, en = events.pop(0) if isinstance(t, int): active_switchers[(x, y)] = (t-1, en) else: active_apples[(x, y)] = en # Deplasare șarpe snake_alive = move_snake() time += 1 # Rezultate if snake_alive: print("LIBER") else: print("BLOCAT") # Harta finală forest = [['.' for _ in range(M)] for _ in range(N)] for x, y in snake: forest[x][y] = 'S' forest[head[0]][head[1]] = 'H' for line in forest: print(''.join(line)) </syntaxhighlight>
Summary:
Please note that all contributions to Bitnami MediaWiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Bitnami MediaWiki:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Toggle limited content width