zoukankan      html  css  js  c++  java
  • Two Teams Composing CodeForces 1335C

    You have nn students under your control and you have to compose exactly two teams consisting of some subset of your students. Each student had his own skill, the ii-th student skill is denoted by an integer aiai (different students can have the same skills).

    So, about the teams. Firstly, these two teams should have the same size. Two more constraints:

    • The first team should consist of students with distinct skills (i.e. all skills in the first team are unique).
    • The second team should consist of students with the same skills (i.e. all skills in the second team are equal).

    Note that it is permissible that some student of the first team has the same skill as a student of the second team.

    Consider some examples (skills are given):

    • [1,2,3][1,2,3], [4,4][4,4] is not a good pair of teams because sizes should be the same;
    • [1,1,2][1,1,2], [3,3,3][3,3,3] is not a good pair of teams because the first team should not contain students with the same skills;
    • [1,2,3][1,2,3], [3,4,4][3,4,4] is not a good pair of teams because the second team should contain students with the same skills;
    • [1,2,3][1,2,3], [3,3,3][3,3,3] is a good pair of teams;
    • [5][5], [6][6] is a good pair of teams.

    Your task is to find the maximum possible size xx for which it is possible to compose a valid pair of teams, where each team size is xx (skills in the first team needed to be unique, skills in the second team should be the same between them). A student cannot be part of more than one team.

    You have to answer tt independent test cases.

    Input

    The first line of the input contains one integer tt (1t1041≤t≤104) — the number of test cases. Then tt test cases follow.

    The first line of the test case contains one integer nn (1n21051≤n≤2⋅105) — the number of students. The second line of the test case contains nn integers a1,a2,,ana1,a2,…,an (1ain1≤ai≤n), where aiai is the skill of the ii-th student. Different students can have the same skills.

    It is guaranteed that the sum of nn over all test cases does not exceed 21052⋅105 (n2105∑n≤2⋅105).

    Output

    For each test case, print the answer — the maximum possible size xx for which it is possible to compose a valid pair of teams, where each team size is xx.

    Example

    Input
    4
    7
    4 2 4 1 4 3 4
    5
    2 1 5 4 3
    1
    1
    4
    1 1 1 3
    
    Output
    3
    1
    0
    2
    

    Note

    In the first test case of the example, it is possible to construct two teams of size 33: the first team is [1,2,4][1,2,4] and the second team is [4,4,4][4,4,4]. Note, that there are some other ways to construct two valid teams of size 33.

    #include <bits/stdc++.h>
    typedef long long ll;
    using namespace std;
    const ll inf = 1e18;
    const int mod = 1000000007;
    const int mx = 100; //check the limits, dummy
    typedef pair<int, int> pa;
    const double PI = acos(-1);
    ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
    #define swa(a,b) a^=b^=a^=b
    #define re(i,a,b) for(int i=(a),_=(b);i<_;i++)
    #define rb(i,a,b) for(int i=(b),_=(a);i>=_;i--)
    #define clr(a) memset(a, 0, sizeof(a))
    #define lowbit(x) ((x)&(x-1))
    #define mkp make_pair
    void sc(int& x) { scanf("%d", &x); }void sc(int64_t& x) { scanf("%lld", &x); }void sc(double& x) { scanf("%lf", &x); }void sc(char& x) { scanf(" %c", &x); }void sc(char* x) { scanf("%s", x); }
    ll  m, n,t,x,k,ans=0,sum=0;
    ll a[mx], b;
    
    int main()
    {
        ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
        cin >> t;
        while (t--) {
            cin >> n;
            vector<int>cnt(n);
            re(i, 0, n) {
                cin >> m;
                --m;
                ++cnt[m];
            }
            int maxx = *max_element(cnt.begin(), cnt.end());
            int cc=0;
            re(i, 0, n) {
                cc += !!cnt[i];
            }
            cout << min(maxx, cc) - (maxx == cc) << endl;
        }
    }
  • 相关阅读:
    【转载】著名黑客雷蒙评价几种编程语言
    【GUI开发】Swing的一本极好的入门教材
    【数据结构】数组操作(HighArrayApp.java)
    数据另存为CSV档案(也是一种excel档案)【2】------自主选择路径
    TIniFile实现打开窗体后还原用户之前的配置的功能
    sql server内连接(inner join)、外连接(left outer join、right outer join、full outer join)、记录合并(union、union all)
    @指针、Cardinal()、Integer()、指针取值解析
    关于php编程的一些小技巧
    数据库操作,同时更新多条数据
    省份,城市,地区------三级联动菜单//要加注释
  • 原文地址:https://www.cnblogs.com/xxxsans/p/12696483.html
Copyright © 2011-2022 走看看