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
4137 - rgb
(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>rgb.in</code> 1 1 2 2 3 1 7 5 9 <code>rgb.out</code> 7 === Explicație === <code>C = 1</code>, deci se va rezolva prima cerinţă. Există un extraterestru roşu, care are puterea <code>3</code>, doi extratereştri verzi, având puterile <code>1</code>, respectiv <code>7</code> şi doi extratereştri albaștri cu puterile <code>5</code>, respectiv <code>9</code>. Extraterestrul cu puterea <code>7</code> este singurul care va câştiga cele mai multe lupte (în cazul acesta, chiar toate): * când luptă cu extraterestrul verde cu puterea <code>1</code> câştigă, pentru că are puterea mai mare; * când luptă cu extraterestrul roşu cu puterea <code>3</code>, acesta îşi va dubla puterea (va avea puterea <code>6</code>), dar va fi insuficient pentru a câștiga lupta; * când luptă contra extraterestrului albastru cu puterea <code>9</code>, va avea puterea dublată (<code>14</code>), prin urmare va câştiga şi această luptă. <syntaxhighlight lang="python" line="1"> def determine_winner_and_counts(N, colors, powers): # Initialize the win counts win_counts = [0] * N for i in range(N): for j in range(i + 1, N): power_i = powers[i] power_j = powers[j] # Adjust powers based on the colors if colors[i] == 'R' and colors[j] == 'G': power_i *= 2 elif colors[i] == 'G' and colors[j] == 'R': power_j *= 2 elif colors[i] == 'G' and colors[j] == 'B': power_i *= 2 elif colors[i] == 'B' and colors[j] == 'G': power_j *= 2 elif colors[i] == 'B' and colors[j] == 'R': power_i *= 2 elif colors[i] == 'R' and colors[j] == 'B': power_j *= 2 # Determine winner if power_i > power_j: win_counts[i] += 1 else: win_counts[j] += 1 # Determine the extraterrestrial with the most wins max_wins = max(win_counts) winners = [powers[i] for i in range(N) if win_counts[i] == max_wins] min_power_winner = min(winners) return min_power_winner, win_counts # Exemplu de utilizare N = 5 colors = ['R', 'G', 'B', 'R', 'G'] powers = [5, 3, 7, 9, 1] min_power_winner, win_counts = determine_winner_and_counts(N, colors, powers) print("Puterea extraterestrului cu cele mai multe lupte câștigate:", min_power_winner) print("Numărul de lupte câștigate de fiecare extraterestru:", win_counts) </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