time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
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 eiei — his inexperience. Russell decided that an explorer with inexperience ee can only join the group of ee 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 TT(1≤T≤2?1051≤T≤2?105). Next 2T2T lines contain description of test cases.
The first line of description of each test case contains the number of young explorers NN (1≤N≤2?1051≤N≤2?105).
The second line contains NN integers e1,e2,…,eNe1,e2,…,eN (1≤ei≤N1≤ei≤N), where eiei is the inexperience of the ii-th explorer.
It's guaranteed that sum of all NN doesn't exceed 3?1053?105.
Output
Print TT numbers, each number on a separate line.
In ii-th line print the maximum number of groups Russell can form in ii-th test case.
Example
input
Copy
2 3 1 1 1 5 2 3 1 2 2
output
Copy
3 2
Note
In the first example we can organize three groups. There will be only one explorer in each group. It's correct because inexperience of each explorer equals to 11, so it's not less than the size of his group.
In the second example we can organize two groups. Explorers with inexperience 11, 22 and 33 will form the first group, and the other two explorers with inexperience equal to 22 will form the second group.
This solution is not unique. For example, we can form the first group using the three explorers with inexperience equal to 22, and the second group using only one explorer with inexperience equal to 11. In this case the young explorer with inexperience equal to 33 will not be included in any group.
解题说明:此题是一道模拟题,题意是经验不足值E的探险者只能加入到人数>=E的团队,因此每组数据都先使用sort排序。使用for循环遍历数组,利用计数器记录人数,比较人数与E值大小即可。
#include
#include
#include
#include
#includeusing namespace std;
int T, n, a[200005];
int main()
{
cin >> T;
while (T--)
{
cin >> n;
int ans = 0, now = 0;
for (int i = 1;
i <= n;
i++)
{
cin >> a[i];
}
sort(a + 1, a + n + 1);
for (int i = 1;
i <= n;
i++)
{
now++;
if (now >= a[i])
{
now = 0;
ans++;
}
}
cout << ans << endl;
}
return 0;
}
【B. Young Explorers】