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
1226 - Nebuni
(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> #1226 Nebuni def verificare_date_intrare(N, M, nebuni): if not (1 <= N <= 1000000): return False if not (1 <= M < 16500): return False for x, y in nebuni: if not (1 <= x <= N and 1 <= y <= N): return False return True def numar_pozitii_sigure(N, M, nebuni): # Inițializăm o matrice pentru tabla de șah și o marcam pe toate pozițiile atacate de nebuni tabla = [[False] * N for _ in range(N)] for x, y in nebuni: for i in range(N): for j in range(N): if abs(x - i) == abs(y - j): tabla[i][j] = True # Numărăm pozițiile sigure care nu sunt atacate de niciun nebun numar_pozitii_sigure = 0 for i in range(N): for j in range(N): if not tabla[i][j]: numar_pozitii_sigure += 1 return numar_pozitii_sigure def main(): # Citim datele de intrare try: with open("nebuni.in", "r") as fin: N, M = map(int, fin.readline().split()) nebuni = [tuple(map(int, line.split())) for line in fin] except ValueError: # Date invalide with open("nebuni.out", "w") as fout: fout.write("Date invalide\n") return # Verificăm datele de intrare if not verificare_date_intrare(N, M, nebuni): with open("nebuni.out", "w") as fout: fout.write("Date de intrare invalide.\n") return # Determinăm numărul de poziții sigure rezultat = numar_pozitii_sigure(N, M, nebuni) # Scriem rezultatul în fișierul de ieșire with open("nebuni.out", "w") as fout: fout.write(str(rezultat) + "\n") 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