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
3244 - tabla
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
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="python3" line="1"> def calculeaza_punctaj(tabla, n, i1, j1, i2, j2): punctaj = 0 # Verificare pe linii if i1 < n - 2 and tabla[i1][j1] == tabla[i1 + 1][j1] == tabla[i1 + 2][j1]: punctaj += 1 if i2 < n - 2 and tabla[i2][j2] == tabla[i2 + 1][j2] == tabla[i2 + 2][j2]: punctaj += 1 # Verificare pe coloane if j1 < n - 2 and tabla[i1][j1] == tabla[i1][j1 + 1] == tabla[i1][j1 + 2]: punctaj += 1 if j2 < n - 2 and tabla[i2][j2] == tabla[i2][j2 + 1] == tabla[i2][j2 + 2]: punctaj += 1 # Verificare pe diagonale if i1 < n - 2 and j1 < n - 2 and tabla[i1][j1] == tabla[i1 + 1][j1 + 1] == tabla[i1 + 2][j1 + 2]: punctaj += 1 if i2 < n - 2 and j2 < n - 2 and tabla[i2][j2] == tabla[i2 + 1][j2 + 1] == tabla[i2 + 2][j2 + 2]: punctaj += 1 return punctaj def cel_mai_mare_punctaj(tabla, n): max_punctaj = 0 for i1 in range(n): for j1 in range(n): for i2 in range(i1, n): for j2 in range(n): # Pentru fiecare pereche de piese alaturate, calculam punctajul if (i1 != i2 or abs(j1 - j2) != 1) and (j1 != j2 or abs(i1 - i2) != 1): tabla[i1][j1], tabla[i2][j2] = tabla[i2][j2], tabla[i1][j1] punctaj = calculeaza_punctaj(tabla, n, i1, j1, i2, j2) max_punctaj = max(max_punctaj, punctaj) tabla[i1][j1], tabla[i2][j2] = tabla[i2][j2], tabla[i1][j1] # revenire la starea initiala return max_punctaj def verificare_date_intrare(n, tabla): if not (1 <= n <= 20): return False for i in range(n): if len(tabla[i]) != n or not all(1 <= tabla[i][j] <= 5 for j in range(n)): return False return True # Citire date de intrare with open("tablain.txt", "r") as file: n = int(file.readline()) tabla = [list(map(int, file.readline().split())) for _ in range(n)] # Verificare date de intrare if not verificare_date_intrare(n, tabla): print("Datele introduse nu corespund restricțiilor impuse") else: # Calcul si afisare rezultat rezultat = cel_mai_mare_punctaj(tabla, n) with open("tablaout.txt", "w") as file: file.write(str(rezultat) + "\n") </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