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
2959 - minecraft
(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> def numara_zona_supravietuire(harta, N): def dfs(i, j): if i < 0 or i >= N or j < 0 or j >= N or harta[i][j] == 'A' or vizitat[i][j]: return vizitat[i][j] = True dfs(i + 1, j) dfs(i - 1, j) dfs(i, j + 1) dfs(i, j - 1) vizitat = [[False] * N for _ in range(N)] zone_supravietuire = 0 for i in range(N): for j in range(N): if harta[i][j] == 'V' and not vizitat[i][j]: zone_supravietuire += 1 dfs(i, j) return zone_supravietuire def zona_maxima_creativ(harta, N): def max_histogram_area(histogram): stack = [] max_area = 0 index = 0 while index < len(histogram): if not stack or histogram[stack[-1]] <= histogram[index]: stack.append(index) index += 1 else: top_of_stack = stack.pop() area = (histogram[top_of_stack] * ((index - stack[-1] - 1) if stack else index)) max_area = max(max_area, area) while stack: top_of_stack = stack.pop() area = (histogram[top_of_stack] * ((index - stack[-1] - 1) if stack else index)) max_area = max(max_area, area) return max_area max_area = 0 dp = [0] * N for i in range(N): for j in range(N): if harta[i][j] == 'V': dp[j] += 1 else: dp[j] = 0 max_area = max(max_area, max_histogram_area(dp)) return max_area def numara_toate_zonele(harta, N): zone_supravietuire = 0 for top in range(N): for left in range(N): for bottom in range(top, N): for right in range(left, N): found_water = False for i in range(top, bottom + 1): for j in range(left, right + 1): if harta[i][j] == 'A': found_water = True if found_water: zone_supravietuire += 1 return zone_supravietuire def main(): K = int(input().strip()) N = int(input().strip()) assert 2 <= N <= 1000, "N trebuie sa fie intre 2 si 1000" harta = [] for _ in range(N): row = list(input().strip()) assert len(row) == N, "Fiecare rând trebuie să aibă exact N caractere" assert all(c in {'A', 'V'} for c in row), "Harta poate contine doar caracterele 'A' si 'V'" harta.append(row) if K == 1: zone_supravietuire = numara_toate_zonele(harta, N) print(f"{zone_supravietuire}") elif K == 2: zona_creativ = zona_maxima_creativ(harta, N) print(f"{zona_creativ}") else: print("Valoare K invalidă") if __name__ == "__main__": main() 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