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
1763 - Pachete2
(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="python3" line="1"> def cmmdc(a, b): while b: a, b = b, a % b return a def check_constraints(num_sets, x_values): # Constraint 1: 1 ≤ N ≤ 100000 if not (1 <= num_sets <= 100000): return False # Constraint 2: Numărul de produse disponibile din fiecare tip este un număr natural nenul cu cel mult 6 cifre. for x_list in x_values: for x in x_list: if not (1 <= x <= 999999): return False return True def handle_constraints_error(g): g.write("Datele nu corespund restrictiilor impuse\n") def main(): try: with open("pachete2IN.txt", "r") as f, open("pachete2OUT.txt", "w") as g: num_sets = int(f.readline()) x_values_list = [] for _ in range(num_sets): x_values = list(map(int, f.readline().split())) x_values_list.append(x_values) if not check_constraints(len(x_values_list), x_values_list): handle_constraints_error(g) return # Exit program if constraints are violated for x_values in x_values_list: n = len(x_values) c = [0] * (n + 1) m = [0] * (n + 1) if n >= 2: x = x_values[0] for i in range(1, n): y = x_values[i] c[i] = cmmdc(x, y) x = y m[1] = 0 m[2] = c[1] for i in range(3, n + 1): m[i] = max(m[i - 1], m[i - 2] + c[i - 1]) result = str(m[n]) if m[n] != 0 else "" g.write(result + '\n') except FileNotFoundError: print("Input file 'pachete2IN.txt' not found.") except Exception as e: print("An error occurred:", e) 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