• Boats Competition solution


    题意

    暴力枚举

    #include <iostream>
    #include<algorithm>
    #include<cstring>
    using namespace std;
    int a[55], ans, mc[105];
    bool vis[55];
    int main()
    {
        int t;
        cin >> t;
        while(t--)
        {
            int n;
            cin >> n;
            ans = 0;
            for(int i = 1; i <= n; i++)
            {
                cin >> a[i];
            }
            sort(a + 1, a + n +1);
            for(int w = 1; w <= a[n] + a[n - 1]; w++)
            {
                int ant = 0;
                memset(mc, 0, sizeof(mc));
                for(int i = 1; i <= n; i++)
                {
                    mc[a[i]]++;
                }
                for(int i = 1; i <= n; i++)
                {
                    if(w - a[i] >= 1 && mc[w - a[i]] && mc[a[i]])
                    {
                        if(w - a[i] == a[i] && mc[w - a[i]] <= 1) continue; 
                        cnt++;
                        mc[w - a[i]]--;
                        mc[a[i]]--;
                    }
                } 
                ans = max(ans, ant);
            }
            cout << ans << endl;
        }
        return 0;
    }
  • 相关阅读:
    poj2263
    poj2304
    低调是态度,也是智慧
    股票操作記錄2
    治病記錄(2013年)
    过年了
    治病記錄
    近段時間學習記錄
    新的一年
    關于設計
  • 原文地址:https://www.cnblogs.com/hrlsm/p/13463970.html
Copyright © 2020-2023  润新知