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
1473 - Grupa Pregătitoare
(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> #1473 def read_input(): with open("grupapregatitoare.in", "r") as in_file: n, p = map(int, in_file.readline().split()) values = [] for _ in range(n): x, y = map(int, in_file.readline().split()) values.append((x, y)) return p, values def validate_input(n, p, values): if not (3 <= n <= 2000): print("Datele introduse nu corespund cerintelor.") exit() if not (2 <= p <= 1000): print("Datele introduse nu corespund cerintelor.") exit() for x, y in values: if not (0 < x < 1001 and 0 < y < 1001): print("numerele de pe cartonas trebuie sa fie nenule si mai mici decat 1001") exit() if x % p == 0 or y % p == 0: return # satisface conditia ca exista cel putin un numar divizibil cu p pe un cartonas print("nu exista cel putin un numar divizibil cu p pe un cartonas") exit() def compute_result(p, values): nr1, nr2 = 0, 0 suma = 0 flag = False minim = 20000 secpar = 0 secimp = 0 lp = 0 li = 0 maxim = 0 lungi = 0 lungp = 0 for x, y in values: if x > y: suma += x else: suma += y if ((x % p == 0) and (x >= y)) or ((y % p == 0) and (y >= x)): flag = True if (x % p == 0) and (x < y) and (y - x < minim): minim = y - x nr1 = x nr2 = y if (y % p == 0) and (y < x) and (x - y < minim): minim = x - y nr1 = y nr2 = x if (x % 2 == 0) or (y % 2 == 0): secpar += 1 else: if lp == 0: lungp = secpar lp = 1 if secpar > maxim: maxim = secpar secpar = 0 if (x % 2 == 1) or (y % 2 == 1): secimp += 1 else: if li == 0: lungi = secimp li = 1 if secimp > maxim: maxim = secimp secimp = 0 if secpar + lungp > maxim: maxim = secpar + lungp if secimp + lungi > maxim: maxim = secimp + lungi return suma, flag, nr1, nr2, maxim def write_output(result): with open("grupapregatitoare.out", "w") as out_file: suma, flag, nr1, nr2, maxim = result if flag: out_file.write(str(suma)) else: out_file.write(str(suma - nr2 + nr1)) out_file.write("\n" + str(maxim)) if __name__ == "__main__": with open("grupapregatitoare.in", "r") as in_file, open("grupapregatitoare.out", "w") as out_file: n, p = map(int, in_file.readline().split()) values = [tuple(map(int, line.split())) for line in in_file] validate_input(n, p, values) result = compute_result(p, values) print("Datele introduse corespund cerintelor.") write_output(result) </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