Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 114 additions & 0 deletions dimik-run-rate-1/bn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@

# রান রেট ১

## সমস্যার সারসংক্ষেপ

৫০ ওভারের একটি ওয়ানডে ক্রিকেট ম্যাচে:

- মোট বল = ৫০ × ৬ = ৩০০ বল
- ইনপুট হিসেবে নিতে হয়:
- r1 → প্রতিপক্ষের মোট রান
- r2 → বর্তমান ব্যাটিং দলের রান
- B → বাকি বলের সংখ্যা

আমাদের বের করতে হবে:

1. বর্তমান রান রেট (Current Run Rate)
2. জয়ের জন্য প্রয়োজনীয় রান রেট (Required Run Rate)

প্রতিটি মান দশমিকের পরে ঠিক দুই ঘর পর্যন্ত প্রিন্ট করতে হবে।

---

## গুরুত্বপূর্ণ নিয়ম

- ৬ বল = ১ ওভার
- জিততে হলে প্রতিপক্ষের চেয়ে অন্তত ১ রান বেশি করতে হবে
- খেলা হয়েছে এমন বল = 300 - B

---

## ব্যাখ্যা

### ১. বর্তমান রান রেট

বর্তমান রান রেট নির্ণয় করা হয় ইতিমধ্যে করা রান এবং খেলা হওয়া বলের উপর ভিত্তি করে।

বর্তমান রান রেট = (r2 × 6) / খেলা হওয়া বল

যেখানে,

খেলা হওয়া বল = 300 - B

৬ দিয়ে গুণ করা হয় কারণ রান রেট ওভারপ্রতি (৬ বল) হিসাব করা হয়।

---

### ২. প্রয়োজনীয় রান রেট

প্রথমে জয়ের জন্য প্রয়োজনীয় রান বের করি:

প্রয়োজনীয় রান = (r1 + 1) - r2

যদি মান ঋণাত্মক হয়, তাহলে ০ ধরা হয়, কারণ দল ইতিমধ্যে জিতে গেছে।

তারপর,

প্রয়োজনীয় রান রেট = (প্রয়োজনীয় রান × 6) / B

এটি বাকি বলগুলিতে ওভারপ্রতি কত রান করতে হবে তা নির্দেশ করে।

---

## সংক্ষেপে

- যদি খেলা হওয়া বল ০ হয়, তাহলে বর্তমান রান রেট 0.00।
- যদি বাকি বল ০ হয়, তাহলে প্রয়োজনীয় রান রেট 0.00।
- যদি দল ইতিমধ্যে জিতে যায়, তাহলে প্রয়োজনীয় রান রেট 0.00।

---

## C++ সমাধান

```cpp
//------ Contributor ~ --------//
//------ MD. S. M. Sarowar Hossain --------//
//------ Varendra University --------//

#include <iostream>
#include <iomanip> //setprecision আর fixed value এর জন্য দরকারি

using namespace std;

int main()
{
int n;
cin >> n;

while (n--)
{
long long r1, r2, B;
cin >> r1 >> r2 >> B;

long long ball_played = 300 - B; //৫০ ওভার = ৫০*৬ = ৩০০ বল

double current_run_rate = 0.0;
if (ball_played > 0){ // যদি একটাও বল না খেলে, তাহলে রান রেট ০.০।
current_run_rate = (r2 * 6.0) / ball_played;
}
double run_needed = (r1 + 1) - r2;
if (run_needed < 0) { //যদি ১ রানের প্রয়োজন হয়, এমন সময় ব্যাটস্‌ম্যান ৪, ৬ রান সংগ্রহ করে,
// তাহলে খণাত্বক সংখ্যা দেখাবে, তাই if দিয়ে এমন ঘটনা এড়াতে হবে
run_needed = 0;
}
double required_run_rate = 0.0;
if (B > 0){
required_run_rate = (run_needed * 6.0) / B;
}
cout << fixed << setprecision(2)
<< current_run_rate << " "
<< required_run_rate << endl;
}

return 0;
}
114 changes: 114 additions & 0 deletions dimik-run-rate-1/en.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
# Run Rate 1

## Problem Summary

In a 50-over ODI cricket match:

- Total balls = 50 × 6 = 300
- We are given:
- r1 → Opponent’s total runs
- r2 → Current runs of batting team
- B → Remaining balls

We need to calculate:

1. Current Run Rate (CRR)
2. Required Run Rate (RRR)

Each value must be printed with exactly two digits after the decimal point.

---

## Important Cricket Rules

- 1 over = 6 balls
- To win, the batting team must score at least 1 run more than the opponent.
- Balls played = 300 - B

---

## Formula Explanation

### 1. Current Run Rate (CRR)

Current Run Rate is calculated based on runs scored and balls already played.

CRR = (r2 × 6) / balls_played

Where:

balls_played = 300 - B

We multiply by 6 because run rate is calculated per over (6 balls).

---

### 2. Required Run Rate (RRR)

First, calculate runs needed to win:

runs_needed = (r1 + 1) - r2

If runs_needed becomes negative, we set it to 0 because the team has already won.

Then,

RRR = (runs_needed × 6) / B

This calculates how many runs per over are required in the remaining balls.

---

## Edge Cases Considered

- If balls_played = 0, CRR is set to 0.00.
- If B = 0, RRR is set to 0.00.
- If the team already won, required run rate becomes 0.00.

---

## C++ Implementation

```cpp
//------ Contributor ~ --------//
//------ MD. S. M. Sarowar Hossain --------//
//------ Varendra University --------//

#include <iostream>
#include <iomanip> // for setprecision and fixed value

using namespace std;

int main()
{
int n;
cin >> n; //test case

while (n--)
{
long long r1, r2, B;
cin >> r1 >> r2 >> B; //three required variables

long long ball_played = 300 - B; // 50 overs = 50 * 6 = 300 balls

double current_run_rate = 0.0; //if no ball played, crr = 0
if (ball_played > 0){
current_run_rate = (r2 * 6.0) / ball_played; //if balls played, calculate the RR
}
double run_needed = (r1 + 1) - r2;
if (run_needed < 0) {
run_needed = 0; //if the player get 2, 3, 4 or 6 runs when 1 run is required,
// the run_needed calculation return (-)negative value, so we need to
// set the value to 0, cause already won the match.
}
double required_run_rate = 0.0;
if (B > 0) {
required_run_rate = (run_needed * 6.0) / B;
}
cout << fixed << setprecision(2)
<< current_run_rate << " "
<< required_run_rate << endl;
}

return 0;
}