Young Explorers

灰太狼 2023-03-14 08:17 85阅读 0赞

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.InputThe first line contains the number of independent test cases T(1≤T≤2⋅105). Next 2Tlines contain description of test cases.The first line of description of each test case contains the number of young explorers NN (1≤N≤2⋅105).The second line contains NN integers e1,e2,…,eN (1≤ei≤N), where eiei is the inexperience of the ii-th explorer.It’s guaranteed that sum of all NN doesn’t exceed 3⋅105.OutputPrint TT 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.
Example
input
2
3
1 1 1
5
2 3 1 2 2
output
3
2
NoteIn 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 1, so it’s not less than the size of his group.In the second example we can organize two groups. Explorers with inexperience 1, 2 and 3will form the first group, and the other two explorers with inexperience equal to 2 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 2, and the second group using only one explorer with inexperience equal to 1. In this case the young explorer with inexperience equal to 3 will not be included in any group.

  1. #include<iostream>
  2. using namespace std;
  3. int main()
  4. {
  5. int t,m=0;
  6. cin>>t;
  7. for(int f=0;f<t;f++)
  8. {
  9. int n=0;
  10. cin>>n;
  11. int a[n],b[n];
  12. for(int i=0;i<n;i++)
  13. {
  14. cin>>a[i];
  15. }
  16. for(int i=0;i<n-1;i++)
  17. {
  18. for(int j=0;j<n-1-i;j++)
  19. {
  20. if(a[j]>a[j+1])
  21. {
  22. int t=a[j];
  23. a[j]=a[j+1];
  24. a[j+1]=t;
  25. }
  26. }
  27. }
  28. for(int k=0;k<n-1;k++)
  29. {
  30. if(a[k]!=a[k+1])
  31. {
  32. b[m++]=a[k];
  33. }
  34. }
  35. if(a[n-2]!=a[n-1])
  36. {
  37. b[m++]=a[n-1];
  38. }
  39. if(m==0)
  40. {
  41. int c1=0;
  42. for(int e=0;e<n;e++)
  43. {
  44. if(a[e]==b[0])
  45. {
  46. c1++;
  47. }
  48. }
  49. cout<<c1<<endl;
  50. }
  51. else if(m>0)
  52. {
  53. int c2=0;
  54. for(int d=0;d<m;d++)
  55. {
  56. int c1=0;
  57. for(int e=0;e<n;e++)
  58. {
  59. if(a[e]==b[d])
  60. {
  61. c1++;
  62. }
  63. }
  64. if(c1>=b[d])
  65. {
  66. c2++;
  67. }
  68. }
  69. cout<<c2<<endl;
  70. }
  71. }
  72. }

发表评论

表情:
评论列表 (有 0 条评论,85人围观)

还没有评论,来说两句吧...

相关阅读

    相关 Log Explorer使用说明

    操作步骤 下载完在数据库服务器中安装客户端和服务端,然后打开Log Explorer,4.2的界面以蓝色为主调,运行软件可见: (1).点击<Attach Log File