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
2164 - munte1
(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>munte1IN.txt</code> 4 1 3 9 10 2 4 11 13 5 6 12 14 7 15 16 19 13 <code>munte1OUT.txt</code> 2 4 == Explicație == Valoarea <code>13</code> se află pe poziția <code>(2,4)</code>. == Exemplul 2: == <code>munte1IN.txt</code> 701 1 3 9 10 2 4 11 13 5 6 12 14 7 15 16 19 13 <code>munte1OUT.txt</code> Datele nu corespund formatului asteptat == Rezolvare == <syntaxhighlight lang="python3" line="1"> def verifica_restricții(n, a, x): if not (1 <= n <= 700): return False if not (0 < x < 2000000000): return False valori_unică = set() for i in range(1, n + 1): for j in range(1, n + 1): if a[i][j] <= 0 or a[i][j] >= 2000000000 or a[i][j] in valori_unică: return False valori_unică.add(a[i][j]) if x not in valori_unică: return False return True def citire(): with open("munte1IN.txt", "r") as fin: n = int(fin.readline().strip()) a = [[0 for _ in range(n + 1)] for _ in range(n + 1)] for i in range(1, n + 1): linie = fin.readline().strip().split() if len(linie) != n: # Verifică dacă linia are lungimea corectă with open("munte1OUT.txt", "w") as fout: fout.write("Datele nu corespund restrictiilor impuse\n") return None, None, None # Returnează None pentru a indica eroarea for j in range(1, n + 1): a[i][j] = int(linie[j - 1]) x = int(fin.readline().strip()) return n, a, x def cautare(i, st, dr, a, x): if st <= dr: if st == dr: if a[i][st] == x: with open("munte1OUT.txt", "w") as fout: fout.write(f"{i} {st}\n") return True else: mid = (st + dr) // 2 if cautare(i, st, mid, a, x): return True if cautare(i, mid + 1, dr, a, x): return True return False def rezolvare(n, a, x): for i in range(1, n + 1): if x >= a[i][1] and x <= a[i][n]: if cautare(i, 1, n, a, x): break if __name__ == "__main__": n, a, x = citire() if n is not None and a is not None and x is not None: # Verifică dacă citirea a fost corectă if verifica_restricții(n, a, x): rezolvare(n, a, x) else: with open("munte1OUT.txt", "w") as fout: fout.write("Datele nu corespund restrictiilor impuse\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