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
1702 - Cristale
(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>cristale.in</code> 1 6 8 5 6 6 1 5 2 6 5 6 9 9 6 1 7 1 2 6 6 9 6 3 4 1 6 2 2 6 3 4 7 4 2 8 8 2 4 7 7 4 6 8 2 7 2 4 4 2 5 <code>cristale.out</code> 2 === Explicație === Se va rezolva cerinţa 1 a problemei. Eşantionul are <code>6</code> rânduri cu câte <code>8</code> molecule pe fiecare rând. Pe acest eşantion observăm o formaţiune cristalizabilă cu celule de tip <code>9</code>, izolată de învelişul special format din celule identice, toate de tip <code>6</code> şi o formaţiune cristalizabilă cu celule de tip <code>7</code>, izolată de învelişul special format din celule identice, toate de tip <code>4</code>. Formaţiunea de <code>3</code> molecule de tip <code>8</code> nu este o formaţiune cristalizabilă întrucât se află pe marginea eşantionului. <syntaxhighlight lang="python" line="1"> def is_valid_position(x, y, M, N): return 0 <= x < M and 0 <= y < N def identify_crystalline_formations(sample, M, N): directions = [ [(0, 0), (0, 1), (0, 2)], # Orizontal [(0, 0), (1, 0), (2, 0)], # Vertical [(0, 0), (0, 1), (1, 0)], # L form [(0, 0), (1, 0), (1, 1)], # Inverse L form ] formations = [] for i in range(M): for j in range(N): for direction in directions: molecules = set() valid = True for dx, dy in direction: x, y = i + dx, j + dy if not is_valid_position(x, y, M, N): valid = False break molecules.add(sample[x][y]) if valid and len(molecules) == 1: formations.append((i, j, direction)) return formations def apply_crystallization(sample, formations, M, N): for (i, j, direction) in formations: surrounding_type = None formation_type = sample[i][j] # Identify the surrounding type for dx, dy in direction: x, y = i + dx, j + dy for nx, ny in [(x-1, y), (x+1, y), (x, y-1), (x, y+1)]: if is_valid_position(nx, ny, M, N) and sample[nx][ny] != formation_type: surrounding_type = sample[nx][ny] break if surrounding_type: break # Apply the crystallization if surrounding_type: for dx, dy in direction: x, y = i + dx, j + dy sample[x][y] = surrounding_type def print_sample(sample): for row in sample: print(' '.join(map(str, row))) # Exemplu de utilizare M = 5 N = 5 sample = [ [1, 1, 1, 2, 3], [1, 4, 2, 3, 2], [4, 2, 3, 2, 2], [2, 2, 3, 1, 4], [3, 1, 4, 4, 4], ] formations = identify_crystalline_formations(sample, M, N) print(f"Formațiuni cristalizabile: {formations}") apply_crystallization(sample, formations, M, N) print("Eșantion după cristalizare:") print_sample(sample) </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