题目
传送门
There are n programmers that you want to split into several non-empty teams. The skill of the i-th programmer is ai. You want to assemble the maximum number of teams from them. There is a restriction for each team: the number of programmers in the team multiplied by the minimum skill among all programmers in the team must be at least x.
Each programmer should belong to at most one team. Some programmers may be left without a team.
Calculate the maximum number of teams that you can assemble.
Input
The first line contains the integer t (1≤t≤1000) — the number of test cases.
The first line of each test case contains two integers n and x (1≤n≤105;1≤x≤109) — the number of programmers and the restriction of team skill respectively.
The second line of each test case contains n integers a1,a2,…,an (1≤ai≤109), where ai is the skill of the i-th programmer.
The sum of n over all inputs does not exceed 105.
Output
For each test case print one integer — the maximum number of teams that you can assemble.
题意:t组样例,开头两个数n,m,分别表示程序员的数量和要分成一组时这组程序猿中能力的最小值乘以这组程序员的数量的最小值m,下面是n个数表示每个程序员的能力值,问你最多能分成几组
思路:本来想着用dp来着想了好大一会没写出来,参考的大佬博客之后发现是贪心,我真是太菜了…我们把数组从大到小排列,一直增加人数直到能分成一组为止,具体看代码
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<sstream>
#include<queue>
#include<stack>
using namespace std;
#define ll long long
ll a[120000];
int t,n,m;
int cmp(int x,int y)//从大到小
{
return x>y;
}
void solve()
{
for(int i=0;i<n;i++)
cin>>a[i];
sort(a,a+n,cmp);
ll sum=0,s=1;
for(int i=0;i<n;i++)
{
if(a[i]*s>=m)
{
s=1;//程序员的数量
sum++;
}
else s++;
}
printf("%lld\n",sum);
}
int main()
{
cin>>t;
while(t--)
{
cin>>n>>m;
solve();
}
}