Skip to content

Commit

Permalink
Solve Strategy Game in python
Browse files Browse the repository at this point in the history
  • Loading branch information
deniscostadsc committed Sep 24, 2024
1 parent 0483d45 commit 7f55977
Show file tree
Hide file tree
Showing 6 changed files with 205 additions and 0 deletions.
17 changes: 17 additions & 0 deletions solutions/beecrowd/1940/1940.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import sys

for line in sys.stdin:
j, r = map(int, line.split())
players_scores = dict(zip(range(1, j + 1), [0] * j))
winner_player = 1
winner_player_points = 0

for points_index, points in enumerate(map(int, input().split())):
player_index = points_index % j + 1
players_scores[player_index] += points

if players_scores[player_index] >= winner_player_points:
winner_player_points = players_scores[player_index]
winner_player = player_index

print(winner_player)
22 changes: 22 additions & 0 deletions solutions/beecrowd/1940/generate_in.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env bash

set -euo pipefail

TESTCASES=90
MAX_J=500
MAX_R=500
MAX_VICTORY_POINTS=100

for _ in $(seq "${TESTCASES}"); do
j="$((RANDOM % MAX_J + 1))"
r="$((RANDOM % MAX_R + 1))"
echo "${j} ${r}"

for i in $(seq "$((j * r))"); do
if [[ ${i} -ne 1 ]]; then
echo -n " "
fi
echo -n "$((RANDOM % MAX_VICTORY_POINTS))"
done
echo
done
90 changes: 90 additions & 0 deletions solutions/beecrowd/1940/in.txt

Large diffs are not rendered by default.

45 changes: 45 additions & 0 deletions solutions/beecrowd/1940/out.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
226
42
40
324
372
103
35
21
2
214
74
154
80
198
330
5
127
173
42
102
4
16
86
213
135
32
21
208
229
10
185
175
56
22
179
4
100
90
94
74
60
55
113
139
61
30 changes: 30 additions & 0 deletions solutions/beecrowd/1940/problem.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
https://judge.beecrowd.com/en/problems/view/1940

# Strategy Game

A strategy game, with J players, is played around a table. The first player is
the player 1, the second to play is the player 2, and so on. Once completed one
round, again the first player makes his move and the order of the players is
repeated again. Every move, a player guarantees a certain amount of Victory
Points. The score of each player is the sum of Victory Points each of your
moves.

Given the number of players, the number of rounds and a list representing
Victory Points in the order they were obtained, you must determine what the
winning player. If more than one player get the highest score, the player with
the highest score that you played last is the winner.

## Input

The input consists of two lines. The first line contains two integers $J$ and
$R$, the number of players and rounds respectively $(1 \leq J, R \leq 500)$. The
second line contains integer $J \times R$ corresponding to Victory Points in
each of the moves made in the order they happened. The Victory Points obtained
in each round will always be integers between 0 and 100, inclusive.

## Output

Your program should produce a single line containing the integer corresponding
to the winning player.


1 change: 1 addition & 0 deletions solutions/beecrowd/1940/tags.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ad-hoc

0 comments on commit 7f55977

Please sign in to comment.