当前位置:网站首页>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;
}
边栏推荐
- 隔离和降级
- excel change cell size
- C#大型互联网平台管理框架源码:基于ASP.NET MVC+EF6+Bootstrap开发,支持多数据库
- Jmeter是什么
- Error creating bean with name ‘dataSource‘:Unsatisfied dependency expressed through field ‘basicPro
- (Translation) How the contrasting color of the button guides the user's actions
- qt-faststart installation and use
- 论文解读(GSAT)《Interpretable and Generalizable Graph Learning via Stochastic Attention Mechanism》
- 最短路模板
- From 0 to 100: Notes on the Development of Enrollment Registration Mini Programs
猜你喜欢

PHP算法之电话号码的字母组合

小程序毕设作品之微信体育馆预约小程序毕业设计成品(3)后台功能

从0到1:图文投票小程序设计与研发笔记

Use Jenkins for continuous integration, this knowledge point must be mastered

下载安装 vscode(含汉化、插件的推荐和安装)

Codeforces CodeTON Round 2 (Div. 1 + Div. 2, Rated, Prizes!) A-D Solution

如何给 UE4 场景添加游戏角色
Background project Express-Mysql-Vue3-TS-Pinia page layout-sidebar menu

E - Integer Sequence Fair

【SeaTunnel】从一个数据集成组件演化成企业级的服务
随机推荐
华为无线设备配置全局双链路冷备份(AC全局配置方式)
E - Integer Sequence Fair
Graph Theory - Strongly Connected Component Condensation + Topological Sort
Codeforces CodeTON Round 2 (Div. 1 + Div. 2, Rated, Prizes!) A-D Solution
excel change cell size
Mini Program Graduation Works WeChat Food Recipe Mini Program Graduation Design Finished Product (8) Graduation Design Thesis Template
从0到1:图文投票小程序设计与研发笔记
下载安装 vscode(含汉化、插件的推荐和安装)
联邦学习在金融领域的发展和应用
excel clear format
IDEA common plugins
(翻译)按钮的对比色引导用户操作的方式
IDEA常用插件
1391D. 505 状压dp
System availability: 3 9s, 4 9s in SRE's mouth... What is it?
选择合适的 DevOps 工具,从理解 DevOps 开始
Calculate the distance between two points
测试岗月薪5-9k,如何实现涨薪到25k?
03、GO语言变量定义、函数
excel remove all carriage return from a cell