Skip to content

Commit 3746ae9

Browse files
committed
test: [20250901] Add (1792)
1 parent 00b1383 commit 3746ae9

File tree

11 files changed

+164
-30
lines changed

11 files changed

+164
-30
lines changed

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ members = [
304304
"problems/problems_3021",
305305
"problems/problems_36",
306306
"problems/problems_37",
307+
"problems/problems_1792",
307308
]
308309

309310
[package]
@@ -630,3 +631,4 @@ solution_3446 = { path = "problems/problems_3446", features = ["solution_3446"]
630631
solution_3021 = { path = "problems/problems_3021", features = ["solution_3021"] }
631632
solution_36 = { path = "problems/problems_36", features = ["solution_36"] }
632633
solution_37 = { path = "problems/problems_37", features = ["solution_37"] }
634+
solution_1792 = { path = "problems/problems_1792", features = ["solution_1792"] }

daily-problems.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"daily": "3670",
2+
"daily": "1792",
33
"plans": ["3663", "problems", "3664", "problems", "3665", "problems", "3668", "problems", "3669", "problems", "3670", "problems"]
44
}

golang/solution_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package golang
22

33
import (
4-
problem "leetCode/problems/problems_37"
4+
problem "leetCode/problems/problems_1792"
55
"testing"
66
)
77

88
func TestSolution(t *testing.T) {
9-
TestEach(t, "37", "problems", problem.Solve)
9+
TestEach(t, "1792", "problems", problem.Solve)
1010
}

problems/problems_1792/Cargo.toml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
[package]
2+
name = "solution_1792"
3+
version = "0.1.0"
4+
edition = "2021"
5+
rust-version = "1.79.0"
6+
authors = ["benhao"]
7+
description = "LeetCode Solution 1792 in Rust"
8+
readme = "../../README.md"
9+
10+
[features]
11+
solution_1792 = []
12+
13+
[dependencies]
14+
serde_json = "1.0"
15+
rand = "0.8.4"
16+
regex = "1.10.5"
17+
library = { path = "../../rust/library", features = ["model"] }
18+
19+
[lib]
20+
name = "solution_1792"
21+
path = "solution.rs"
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//go:build ignore
2+
#include "cpp/common/Solution.h"
3+
4+
5+
using namespace std;
6+
using json = nlohmann::json;
7+
8+
class Solution {
9+
public:
10+
double maxAverageRatio(vector<vector<int>>& classes, int extraStudents) {
11+
12+
}
13+
};
14+
15+
json leetcode::qubh::Solve(string input_json_values) {
16+
vector<string> inputArray;
17+
size_t pos = input_json_values.find('\n');
18+
while (pos != string::npos) {
19+
inputArray.push_back(input_json_values.substr(0, pos));
20+
input_json_values = input_json_values.substr(pos + 1);
21+
pos = input_json_values.find('\n');
22+
}
23+
inputArray.push_back(input_json_values);
24+
25+
Solution solution;
26+
vector<vector<int>> classes = json::parse(inputArray.at(0));
27+
int extraStudents = json::parse(inputArray.at(1));
28+
return solution.maxAverageRatio(classes, extraStudents);
29+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package problems.problems_1792;
2+
3+
import com.alibaba.fastjson.JSON;
4+
import java.util.*;
5+
import qubhjava.BaseSolution;
6+
7+
8+
public class Solution extends BaseSolution {
9+
public double maxAverageRatio(int[][] classes, int extraStudents) {
10+
11+
}
12+
13+
@Override
14+
public Object solve(String[] inputJsonValues) {
15+
int[][] classes = jsonArrayToInt2DArray(inputJsonValues[0]);
16+
int extraStudents = Integer.parseInt(inputJsonValues[1]);
17+
return JSON.toJSON(maxAverageRatio(classes, extraStudents));
18+
}
19+
}

problems/problems_1792/problem.md

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,35 @@
11
# 1792. Maximum Average Pass Ratio [Rating: 1818.00]
22

3-
There is a school that has classes of students and each class will be having a final exam. You are given a 2D integer array `classes`, where `classes[i] = [passi, totali]`. You know beforehand that in the `ith`class, there are `totali` total students, but only `passi` number of students will pass the exam.
3+
<p>There is a school that has classes of students and each class will be having a final exam. You are given a 2D integer array <code>classes</code>, where <code>classes[i] = [pass<sub>i</sub>, total<sub>i</sub>]</code>. You know beforehand that in the <code>i<sup>th</sup></code> class, there are <code>total<sub>i</sub></code> total students, but only <code>pass<sub>i</sub></code> number of students will pass the exam.</p>
44

5-
You are also given an integer `extraStudents`. There are another `extraStudents` brilliant students that are **guaranteed** to pass the exam of any class they are assigned to. You want to assign each of the `extraStudents` students to a class in a way that **maximizes** the **average** pass ratio across **all** the classes.
5+
<p>You are also given an integer <code>extraStudents</code>. There are another <code>extraStudents</code> brilliant students that are <strong>guaranteed</strong> to pass the exam of any class they are assigned to. You want to assign each of the <code>extraStudents</code> students to a class in a way that <strong>maximizes</strong> the <strong>average</strong> pass ratio across <strong>all</strong> the classes.</p>
66

7-
The **pass ratio** of a class is equal to the number of students of the class that will pass the exam divided by the total number of students of the class. The **average pass ratio** is the sum of pass ratios of all the classes divided by the number of the classes.
7+
<p>The <strong>pass ratio</strong> of a class is equal to the number of students of the class that will pass the exam divided by the total number of students of the class. The <strong>average pass ratio</strong> is the sum of pass ratios of all the classes divided by the number of the classes.</p>
88

9-
Return *the **maximum** possible average pass ratio after assigning the* `extraStudents` *students.* Answers within 10<sup>-5</sup> of the actual answer will be accepted.
9+
<p>Return <em>the <strong>maximum</strong> possible average pass ratio after assigning the </em><code>extraStudents</code><em> students. </em>Answers within <code>10<sup>-5</sup></code> of the actual answer will be accepted.</p>
1010

11-
11+
<p>&nbsp;</p>
12+
<p><strong class="example">Example 1:</strong></p>
1213

13-
**Example 1:**
14+
<pre>
15+
<strong>Input:</strong> classes = [[1,2],[3,5],[2,2]], <code>extraStudents</code> = 2
16+
<strong>Output:</strong> 0.78333
17+
<strong>Explanation:</strong> You can assign the two extra students to the first class. The average pass ratio will be equal to (3/4 + 3/5 + 2/2) / 3 = 0.78333.
18+
</pre>
1419

15-
```
16-
Input: classes = [[1,2],[3,5],[2,2]], extraStudents = 2
17-
Output: 0.78333
18-
Explanation: You can assign the two extra students to the first class. The average pass ratio will be equal to (3/4 + 3/5 + 2/2) / 3 = 0.78333.
19-
```
20+
<p><strong class="example">Example 2:</strong></p>
2021

21-
**Example 2:**
22+
<pre>
23+
<strong>Input:</strong> classes = [[2,4],[3,9],[4,5],[2,10]], <code>extraStudents</code> = 4
24+
<strong>Output:</strong> 0.53485
25+
</pre>
2226

23-
```
24-
Input: classes = [[2,4],[3,9],[4,5],[2,10]], extraStudents = 4
25-
Output: 0.53485
26-
```
27-
28-
29-
30-
**Constraints:**
31-
32-
- 1 <= classes.length <= 10<sup>5</sup>
33-
- `classes[i].length == 2`
34-
- 1 <= passi <= totali <= 10<sup>5</sup>
35-
- 1 <= extraStudents <= 10<sup>5</sup>
27+
<p>&nbsp;</p>
28+
<p><strong>Constraints:</strong></p>
3629

30+
<ul>
31+
<li><code>1 &lt;= classes.length &lt;= 10<sup>5</sup></code></li>
32+
<li><code>classes[i].length == 2</code></li>
33+
<li><code>1 &lt;= pass<sub>i</sub> &lt;= total<sub>i</sub> &lt;= 10<sup>5</sup></code></li>
34+
<li><code>1 &lt;= extraStudents &lt;= 10<sup>5</sup></code></li>
35+
</ul>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# 1792. 最大平均通过率 [难度分: 1818.00]
2+
3+
<p>一所学校里有一些班级,每个班级里有一些学生,现在每个班都会进行一场期末考试。给你一个二维数组 <code>classes</code> ,其中 <code>classes[i] = [pass<sub>i</sub>, total<sub>i</sub>]</code> ,表示你提前知道了第 <code>i</code> 个班级总共有 <code>total<sub>i</sub></code> 个学生,其中只有 <code>pass<sub>i</sub></code> 个学生可以通过考试。</p>
4+
5+
<p>给你一个整数 <code>extraStudents</code> ,表示额外有 <code>extraStudents</code> 个聪明的学生,他们 <strong>一定</strong> 能通过任何班级的期末考。你需要给这 <code>extraStudents</code> 个学生每人都安排一个班级,使得 <strong>所有</strong> 班级的 <strong>平均</strong> 通过率 <strong>最大</strong> 。</p>
6+
7+
<p>一个班级的 <strong>通过率</strong> 等于这个班级通过考试的学生人数除以这个班级的总人数。<strong>平均通过率</strong> 是所有班级的通过率之和除以班级数目。</p>
8+
9+
<p>请你返回在安排这 <code><span style="">extraStudents</span></code> 个学生去对应班级后的 <strong>最大</strong> 平均通过率。与标准答案误差范围在 <code>10<sup>-5</sup></code> 以内的结果都会视为正确结果。</p>
10+
11+
<p> </p>
12+
13+
<p><strong>示例 1:</strong></p>
14+
15+
<pre>
16+
<b>输入:</b>classes = [[1,2],[3,5],[2,2]], <code>extraStudents</code> = 2
17+
<b>输出:</b>0.78333
18+
<b>解释:</b>你可以将额外的两个学生都安排到第一个班级,平均通过率为 (3/4 + 3/5 + 2/2) / 3 = 0.78333 。
19+
</pre>
20+
21+
<p><strong>示例 2:</strong></p>
22+
23+
<pre>
24+
<b>输入:</b>classes = [[2,4],[3,9],[4,5],[2,10]], <code>extraStudents</code> = 4
25+
<strong>输出:</strong>0.53485
26+
</pre>
27+
28+
<p> </p>
29+
30+
<p><strong>提示:</strong></p>
31+
32+
<ul>
33+
<li><code>1 <= classes.length <= 10<sup>5</sup></code></li>
34+
<li><code>classes[i].length == 2</code></li>
35+
<li><code>1 <= pass<sub>i</sub> <= total<sub>i</sub> <= 10<sup>5</sup></code></li>
36+
<li><code>1 <= extraStudents <= 10<sup>5</sup></code></li>
37+
</ul>

problems/problems_1792/solution.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
use serde_json::{json, Value};
2+
3+
pub struct Solution;
4+
5+
impl Solution {
6+
pub fn max_average_ratio(classes: Vec<Vec<i32>>, extra_students: i32) -> f64 {
7+
8+
}
9+
}
10+
11+
#[cfg(feature = "solution_1792")]
12+
pub fn solve(input_string: String) -> Value {
13+
let input_values: Vec<String> = input_string.split('\n').map(|x| x.to_string()).collect();
14+
let classes: Vec<Vec<i32>> = serde_json::from_str(&input_values[0]).expect("Failed to parse input");
15+
let extra_students: i32 = serde_json::from_str(&input_values[1]).expect("Failed to parse input");
16+
json!(Solution::max_average_ratio(classes, extra_students))
17+
}

problems/problems_1792/solution.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
function maxAverageRatio(classes: number[][], extraStudents: number): number {
2+
3+
};
4+
5+
export function Solve(inputJsonElement: string): any {
6+
const inputValues: string[] = inputJsonElement.split("\n");
7+
const classes: number[][] = JSON.parse(inputValues[0]);
8+
const extraStudents: number = JSON.parse(inputValues[1]);
9+
return maxAverageRatio(classes, extraStudents);
10+
}

0 commit comments

Comments
 (0)