zoukankan      html  css  js  c++  java
  • Educational Codeforces Round 91 (Rated for Div. 2) C. Create The Teams(贪心/排序)

    There are nn programmers that you want to split into several non-empty teams. The skill of the ii -th programmer is aiai . 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 xx .

    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 tt (1≤t≤10001≤t≤1000 ) — the number of test cases.

    The first line of each test case contains two integers nn and xx (1≤n≤105;1≤x≤1091≤n≤105;1≤x≤109 ) — the number of programmers and the restriction of team skill respectively.

    The second line of each test case contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤1091≤ai≤109 ), where aiai is the skill of the ii -th programmer.

    The sum of nn over all inputs does not exceed 105105 .

    Output

    For each test case print one integer — the maximum number of teams that you can assemble.

    Example

    Input

    Copy

    3

    5 10

    7 11 2 9 5

    4 8

    2 4 2 3

    4 11

    1 3 3 7

    Output

    Copy

    2

    1

    0

    首先要把原序列排序。然后就是从小到大排序还是从大到小排序的问题。如果从小到大的话,受限于前面的元素,如果前面的元素很小的话,比如a[1] = 1, x = 100,就浪费了很多大的元素,因此需要从后往前来凑组。用变量记录当前组的成员数,当前组最小值以及答案,O(n)扫一遍即可。

    #include <bits/stdc++.h>
    using namespace std;
    int n, x, a[100005];
    int main()
    {
        int t;
        cin >> t;
        while(t--){
            cin >> n >> x;
            for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
            sort(a + 1, a + n + 1);
            int ans = 0, cnt = 1, mmin = a[n];
            for(int i = n - 1; i >= 0; i--){
                if(mmin * cnt >= x){
                    ans++;
                    mmin = a[i];
                    cnt = 1;
                } else{
                    mmin = a[i];
                    cnt++;
                }
            }
            cout << ans << endl;
        }
     
        return 0;
    }
  • 相关阅读:
    怎么加载用户自定义控件
    一个C#委托的示例
    signed add
    避免QuartusII中将没有进行定义的信号自动生成wrie类型
    serial_to_parallel
    用modelsim仿真——对文件的操作
    base of logic
    blocking PK nonblocking
    parallel to serial
    使用signalTapII看综合掉的wrie和register的值
  • 原文地址:https://www.cnblogs.com/lipoicyclic/p/13297310.html
Copyright © 2011-2022 走看看