2025.1.19——1300

2025.1.19——1300


A 1300

You are given an array \(a\) consisting of \(n\) positive integers. You can perform the following operation on it:

  1. Choose a pair of elements \(a_i\) and \(a_j\) (\(1 \le i, j \le n\) and \(i \neq j\));
  2. Choose one of the divisors of the integer \(a_i\), i.e., an integer \(x\) such that \(a_i \bmod x = 0\);
  3. Replace \(a_i\) with \(\frac{a_i}{x}\) and \(a_j\) with \(a_j \cdot x\).

Determine whether it is possible to make all elements in the array the same by applying the operation a certain number of times (possibly zero).

For example, let's consider the array \(a\) = [\(100, 2, 50, 10, 1\)] with \(5\) elements. Perform two operations on it:

  1. Choose \(a_3 = 50\) and \(a_2 = 2\), \(x = 5\). Replace \(a_3\) with \(\frac{a_3}{x} = \frac{50}{5} = 10\), and \(a_2\) with \(a_2 \cdot x = 2 \cdot 5 = 10\). The resulting array is \(a\) = [\(100, 10, 10, 10, 1\)];
  2. Choose \(a_1 = 100\) and \(a_5 = 1\), \(x = 10\). Replace \(a_1\) with \(\frac{a_1}{x} = \frac{100}{10} = 10\), and \(a_5\) with \(a_5 \cdot x = 1 \cdot 10 = 10\). The resulting array is \(a\) = [\(10, 10, 10, 10, 10\)].

After performing these operations, all elements in the array \(a\) become equal to \(10\).
Input

The first line of the input contains a single integer \(t\) (\(1 \le t \le 2000\)) — the number of test cases.

Then follows the description of each test case.

The first line of each test case contains a single integer \(n\) (\(1 \le n \le 10^4\)) — the number of elements in the array \(a\).

The second line of each test case contains exactly \(n\) integers \(a_i\) (\(1 \le a_i \le 10^6\)) — the elements of the array \(a\).

It is guaranteed that the sum of \(n\) over all test cases does not exceed \(10^4\).


B 1300

You have \(n\) sets of integers \(S_{1}, S_{2}, \ldots, S_{n}\). We call a set \(S\) attainable, if it is possible to choose some (possibly, none) of the sets \(S_{1}, S_{2}, \ldots, S_{n}\) so that \(S\) is equal to their union\(^{\dagger}\). If you choose none of \(S_{1}, S_{2}, \ldots, S_{n}\), their union is an empty set.

Find the maximum number of elements in an attainable \(S\) such that \(S \neq S_{1} \cup S_{2} \cup \ldots \cup S_{n}\).

\(^{\dagger}\) The union of sets \(A_1, A_2, \ldots, A_k\) is defined as the set of elements present in at least one of these sets. It is denoted by \(A_1 \cup A_2 \cup \ldots \cup A_k\). For example, \(\{2, 4, 6\} \cup \{2, 3\} \cup \{3, 6, 7\} = \{2, 3, 4, 6, 7\}\).
Input

Each test contains multiple test cases. The first line contains the number of test cases \(t\) (\(1 \le t \le 100\)). The description of the test cases follows.

The first line of each test case contains a single integer \(n\) (\(1 \le n \le 50\)).

The following \(n\) lines describe the sets \(S_1, S_2, \ldots, S_n\). The \(i\)-th of these lines contains an integer \(k_{i}\) (\(1 \le k_{i} \le 50\)) — the number of elements in \(S_{i}\), followed by \(k_{i}\) integers \(s_{i, 1}, s_{i, 2}, \ldots, s_{i, k_{i}}\) (\(1 \le s_{i, 1} < s_{i, 2} < \ldots < s_{i, k_{i}} \le 50\)) — the elements of \(S_{i}\).



------------------------思考------------------------

  • 数学+思维/入手点


A

  1. 本质操作是移动因子/质因子。
  2. 从结果来看,分解质因数后发现每个质因子出现的次数都必须为 \(n\) 的倍数。具有充分必要性。

B

  1. 入手点是枚举每个数:当此数不在最后集合中时,暴力统计有多少元素没有受到影响。最后坏情况大约 6e7 , 600ms 。
  2. 搞了半天数据结构维护,原来暴力就行。

------------------------代码------------------------

A

#include <bits/stdc++.h>
#define int long long //
#define endl '\n'     // attention: interactive/debug
#define el cout << endl
using namespace std;
#define bug(BUG) cout << "bug:# " << (BUG) << endl
#define bug2(BUG1, BUG2) cout << "bug:# " << (BUG1) << " " << (BUG2) << endl
#define bug3(BUG1, BUG2, BUG3) cout << "bug:# " << (BUG1) << ' ' << (BUG2) << ' ' << (BUG3) << endl
#define bugv(VEC, ST)                     \
    for (int i = ST; i < VEC.size(); i++) \
        cout << VEC[i] << ' ';            \
    el;

void _();
signed main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cout << fixed << setprecision(10);
    int T = 1;
    cin >> T;
    while (T--)
        _();
    return 0;
}

void _()
{
    int n;
    cin >> n;
    map<int, int> cnt;
    for (int i = 0; i < n; i++)
    {
        int x;
        cin >> x;
        for (int j = 2; j <= x / j && x; j++)
            while (x % j == 0)
            {
                cnt[j]++;
                x /= j;
            }
        if (x - 1)
            cnt[x]++;
    }
    // for (auto [x, has] : cnt)
    //     bug2(x, has);
    bool f = 1;
    for (auto [x, has] : cnt)
        if (has % n)
            f = 0;
    cout << (f ? "YES" : "NO");
    el;
}

B

#include <bits/stdc++.h>
#define int long long //
#define endl '\n'     // attention: interactive/debug
#define el cout << endl
using namespace std;
#define bug(BUG) cout << "bug:# " << (BUG) << endl
#define bug2(BUG1, BUG2) cout << "bug:# " << (BUG1) << " " << (BUG2) << endl
#define bug3(BUG1, BUG2, BUG3) cout << "bug:# " << (BUG1) << ' ' << (BUG2) << ' ' << (BUG3) << endl
#define bugv(VEC, ST)                                    \
    for (auto i = VEC.begin() + ST; i != VEC.end(); i++) \
        cout << *i << ' ';                               \
    el;

void _();
signed main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cout << fixed << setprecision(10);
    int T = 1;
    cin >> T;
    while (T--)
        _();
    return 0;
}

void _()
{
    int n;
    cin >> n;
    vector<set<int>> has(n);
    set<int> t;

    for (auto &s : has)
    {
        int cnt;
        cin >> cnt;
        for (int i = 0; i < cnt; i++)
        {
            int x;
            cin >> x;
            s.insert(x);
            t.insert(x);
        }
    }

    n = t.size();
    int res = 0;
    for (auto x : t)
    {
        set<int> left;
        for (auto s : has)
        {
            auto it = s.lower_bound(x);
            // bug(*it);
            if (it == s.end() || *it != x)
                for (auto k : s)
                    left.insert(k);
        }

        // bug2(x, left.size());
        res = max(res, (int)left.size());
    }
    cout << res << endl;
}
// void _()
// {
//     int n;
//     cin >> n;
//     map<int, map<int, int>> has;

//     for (int i = 0; i < n; i++)
//     {
//         int cnt;
//         cin >> cnt;
//         set<int> s;
//         for (int i = 0; i < cnt; i++)
//         {
//             int x;
//             cin >> x;
//             s.insert(x);
//         }
//         for (auto x : s)
//             for (auto y : s)
//                 has[x][y]++;
//     }
//     map<int, int> w;
//     for (auto [x, hs] : has)
//     {
//         int c = 0;
//         for (auto [y, cnt] : hs)
//             c += cnt == 1;
//         w[x] = c;
//     }
//     int res = 0;
//     for (auto [x, v] : w)
//         res = max(res, (int)w.size() - v), bug2(x, v);
//     cout << res << endl;
// }

posted @ 2025-01-20 19:24  Jkke  阅读(47)  评论(0)    收藏  举报