七月十三日训练总结
发布日期:2021-05-04 19:40:00 浏览次数:46 分类:原创文章

本文共 1750 字,大约阅读时间需要 5 分钟。

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.

Example
Input
3
5 10
7 11 2 9 5
4 8
2 4 2 3
4 11
1 3 3 7
Output
2
1
0
补一下c题 ,这是今天一开始自己做并没有思路的题目,是看过题解才弄明白的,题目大意就是有N个人要分组,每个人若有组则只参加一组,每个人有技能值 ,组队要求为:组员人数与组员中最低技能值的乘积要不小于x。问最多可以分几组。
做的话就是一个贪心的题目,要分最多组肯定是每组的人数越少越好。当人数越少时,为了满足限制,则需要组内最低技能值高,因此从大到小遍历所有人,判断当前人数和最低技能值的乘积是否够组成一个组就可以了

#include <iostream>#include <algorithm>using namespace std;int a[100005];int main(){       int t;    cin>>t;    while(t--){           int n,x; cin>>n>>x;        for(int i=0;i<n;i++){               cin>>a[i];        }        sort(a,a+n);        int ans=0;int cnt = 0;        int k = n;        while(k--){               cnt++;            if(cnt*a[k]>=x){                   ans++;                cnt = 0;            }        }        cout<<ans<<endl;    }    return 0;}
上一篇:七月十四日训练总结
下一篇:七月十一日训练总结

发表评论

最新留言

哈哈,博客排版真的漂亮呢~
[***.90.31.176]2025年03月14日 19时22分11秒