当前位置:网站首页>6133. 分组的最大数量
6133. 分组的最大数量
2022-08-01 23:08:00 【Mr Gao】
6133. 分组的最大数量
给你一个正整数数组 grades ,表示大学中一些学生的成绩。你打算将 所有 学生分为一些 有序 的非空分组,其中分组间的顺序满足以下全部条件:
第 i 个分组中的学生总成绩 小于 第 (i + 1) 个分组中的学生总成绩,对所有组均成立(除了最后一组)。
第 i 个分组中的学生总数 小于 第 (i + 1) 个分组中的学生总数,对所有组均成立(除了最后一组)。
返回可以形成的 最大 组数。
示例 1:
输入:grades = [10,6,12,7,3,5]
输出:3
解释:下面是形成 3 个分组的一种可行方法:
- 第 1 个分组的学生成绩为 grades = [12] ,总成绩:12 ,学生数:1
- 第 2 个分组的学生成绩为 grades = [6,7] ,总成绩:6 + 7 = 13 ,学生数:2
- 第 3 个分组的学生成绩为 grades = [10,3,5] ,总成绩:10 + 3 + 5 = 18 ,学生数:3
可以证明无法形成超过 3 个分组。
示例 2:
输入:grades = [8,8]
输出:1
解释:只能形成 1 个分组,因为如果要形成 2 个分组的话,会导致每个分组中的学生数目相等。
这一题看似很难,其实在迷惑人,解题代码如下:
int maximumGroups(int* grades, int gradesSize){
for(int i=1;i<1000;i++){
int a=(i+1)*i/2;
if(a>gradesSize){
return i-1;
}
}
return 0;
}
边栏推荐
- Deep Learning Course2 Week 2 Optimization Algorithms Exercises
- 计算两点之间的距离
- xctf attack and defense world web master advanced area webshell
- How to add a game character to a UE4 scene
- String - Trie
- 从0到100:招生报名小程序开发笔记
- excel edit a cell without double clicking
- When using DocumentFragments add a large number of elements
- 解决端口占用
- excel split text into different rows
猜你喜欢
随机推荐
ping no reply
qt-faststart installation and use
Error creating bean with name ‘dataSource‘:Unsatisfied dependency expressed through field ‘basicPro
CF1703G Good Key, Bad Key
PDF转Word有那么难吗?做一个文件转换器,都解决了
Nacos配置中心之加载配置
03、GO语言变量定义、函数
Postman batch test interface detailed tutorial
Jmeter是什么
Go 微服务开发框架DMicro的设计思路
JS prototype hasOwnProperty in Add method Prototype end point Inherit Override parent class method
系统可用性:SRE口中的3个9,4个9...到底是个什么东西?
From 0 to 100: Notes on the Development of Enrollment Registration Mini Programs
Deep learning Course2 first week Practical aspects of Deep Learning exercises
华为无线设备配置双链路冷备份(AP指定配置方式)
Use Jenkins for continuous integration, this knowledge point must be mastered
excel vertical to horizontal
How to add a game character to a UE4 scene
npm npm
How to use pywinauto and pyautogui to link the anime lady and sister please go home