# CRICBZ Editorial

Author - mukul166
Tester - imranasuman

Easy

Simple Maths

# PROBLEM:

A cricket game is played where each over contains M balls.A total of N balls is played and there is P players .We have to find who will be on strike if there is no balls to bowl or who will be on non-strike if there is no player left to come on the crease.

# QUICK EXPLANATION:

As problems is very simple we have to just think about on strike player and non-strike player.

# EXPLANATION:

There are two cases. First, if all N-1 players are out, and Second, after m balls, the player on strike. In both the cases we have to find number of overs which have to be played in the game. In the case of non strike overs will be ceil((players-1)/balls). We have to check if players-1 is less than equal to balls because one player is on non-strike until the over doesnâ€™t change. If we observe for 6 balls in one over then we can see that in first over player 2 will be on non-strike, player 8 will on non-strike in second over, player 14 will on non-strike in third over and so onâ€¦
So, we have to add 2 to our ans .So total answer for non-strike end will be
(over-1)*balls_per_over + 2.
In the second case, in same way we have to find overs. Here overs will be ceil(n/m). So our answer for strike end will be ceil(n/m) + 2 + n%m. Here why we are adding n%m because in the next over the player which was on non-strike in the last over will come to on strike, since n%m balls are remaining so (non-strike end player no + n%m ) will give the number of player who will be on strike.

# SOLUTIONS:

Author's Solution

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define tc(t) while(tâ€“)
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);

int main() {
fio;
ll t;
t = 1;
cin >> t;
tc(t) {
ll players, balls_per_over, total_balls;
cin >> players >> balls_per_over >> total_balls;
players -= 1;
ll over;
if (players > total_balls) over = ceil((1.0 * total_balls) / balls_per_over);
else {
over = ceil((1.0 * players) / balls_per_over);
}
ll on_strike_player = (over - 1) * balls_per_over + 2;
ll non_strike_player = on_strike_player + (total_balls % balls_per_over);
if (players <= total_balls) cout << on_strike_player << â€ś\nâ€ť;
else cout << non_strike_player << â€ś\nâ€ť;
}
return 0;
}

Tester's Solution

#include <bits/stdc++.h>
using namespace std;#
define ll long long
int main() {
ll p, m, n, t, k;
cin >> t;
while (tâ€“) {
cin >> p >> m >> n;
if (p - 1 <= n) {
pâ€“;
if (p % m == 0) {
k = p / m;
} else {
k = p / m + 1;
}
cout << (k - 1) * m + 2 << â€ś\nâ€ť;
} else {
if (n % m == 0) {
k = n / m;
} else {
k = n / m + 1;
}
cout << (k - 1) * m + 2 + (n % m) << â€ś\nâ€ť;
}
}
return 0;
}

1 Like