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
3463 - Lumini 2
(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!
== Rezolvare == <syntaxhighlight lang="python" line> import math def citire_date(): with open("lumini.in", "r") as f: N, M, C = map(int, f.readline().split()) matrice = [] for _ in range(N): linie = [] for _ in range(M): r, g, b = map(int, f.readline().split()) linie.append((r, g, b)) matrice.append(linie) return N, M, C, matrice def dispersie(rgb): r, g, b = rgb sum_rgb = r + g + b if sum_rgb == 0: return 0 return int(((r / sum_rgb) ** 2 + (g / sum_rgb) ** 2 + (b / sum_rgb) ** 2) * 1000) def perechi_conexe(N, M, matrice): directii = [(-1, 0), (1, 0), (0, -1), (0, 1)] vizitat = [[False] * M for _ in range(N)] def dfs(x, y): stack = [(x, y)] vizitat[x][y] = True while stack: cx, cy = stack.pop() for dx, dy in directii: nx, ny = cx + dx, cy + dy if 0 <= nx < N and 0 <= ny < M and not vizitat[nx][ny]: if dispersie(matrice[cx][cy]) == dispersie(matrice[nx][ny]): vizitat[nx][ny] = True stack.append((nx, ny)) componente = 0 for i in range(N): for j in range(M): if not vizitat[i][j]: dfs(i, j) componente += 1 return componente def numar_maxim_P(N, M, matrice): P_max = 0 for i in range(N): for j in range(M): for di, dj in [(-1, 0), (1, 0), (0, -1), (0, 1)]: ni, nj = i + di, j + dj if 0 <= ni < N and 0 <= nj < M: r1, g1, b1 = matrice[i][j] r2, g2, b2 = matrice[ni][nj] if r1 + r2 <= 255 and g1 + g2 <= 255 and b1 + b2 <= 255: P_max = max(P_max, r1 + r2 + g1 + g2 + b1 + b2) return P_max def scrie_rezultate(rezultat): with open("lumini.out", "w") as f: f.write(f"{rezultat}\n") def main(): N, M, C, matrice = citire_date() # Verificarea restrictiilor assert 1 <= N <= 1000, "N trebuie sa fie intre 1 si 1000" assert 1 <= M <= 1000, "M trebuie sa fie intre 1 si 1000" assert 1 <= C <= 2, "C trebuie sa fie 1 sau 2" if C == 1: rezultat = perechi_conexe(N, M, matrice) elif C == 2: rezultat = numar_maxim_P(N, M, matrice) scrie_rezultate(rezultat) if __name__ == "__main__": main() </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