B - Young Explorers

题干

Young wilderness explorers set off to their first expedition led by senior explorer Russell. Explorers went into a forest, set up a camp and decided to split into groups to explore as much interesting locations as possible. Russell was trying to form groups, but ran into some difficulties…
Most of the young explorers are inexperienced, and sending them alone would be a mistake. Even Russell himself became senior explorer not long ago. Each of young explorers has a positive integer parameter ei — his inexperience. Russell decided that an explorer with inexperience e can only join the group of e or more people.
Now Russell needs to figure out how many groups he can organize. It’s not necessary to include every explorer in one of the groups: some can stay in the camp. Russell is worried about this expedition, so he asked you to help him.
Input
The first line contains the number of independent test cases T(1≤T≤2?105). Next 2T lines contain description of test cases.
The first line of description of each test case contains the number of young explorers N (1≤N≤2?105).
The second line contains N integers e1,e2,…,eN (1≤ei≤N), where ei is the inexperience of the i-th explorer.
It’s guaranteed that sum of all N doesn’t exceed 3?105.
Output
Print T numbers, each number on a separate line.
In i-th line print the maximum number of groups Russell can form in i-th test case.
题解
【B - Young Explorers】题意:经验不足值E的探险者只能加入到人数>=E的团队。
因此每组数据都先使用sort排序
使用for循环遍历数组
利用计数器记录人数
比较人数与E值大小
符合要求的情况计数器清零,答案++
代码
#include using namespace std; int t,n,a[300010]; int main(){ cin>>t; while(t--){ cin>>n; for(int i=1; i<=n; i++) cin>>a[i]; sort(a+1,a+1+n); int ans=0,cnt=0; for(int i=1; i<=n; i++){ cnt++; if(cnt>=a[i]){ cnt=0; ans++; } } cout<

    推荐阅读