1355B - Young Explorers

题目:https://codeforces.com/problemset/problem/1355/B


题意:

ei必需存在于>=ei人数的队伍中,求最多可以分多少个队伍。


题解:

我们可以得知,我们需要一满足条件就去组成下一个队伍,这样才可以最大化,因此应该对小的数先处理

我们从小到大排序,然后一有cnt>=a[i]就ans++,cnt=0。


#include 
#include 
using namespace std;
const int N = 2e5 + 5;int a[N];
int main()
{int t;cin >> t;while (t--){int n;cin >> n;for (int i = 0; i < n; i++)cin >> a[i];sort(a, a + n);int cnt = 0, ans = 0;for (int i = 0; i < n; i++){cnt++;if (cnt >= a[i]){cnt = 0;ans++;}}cout << ans << endl;}
}


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部