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 ai and aj (1i,jn and ij);
  2. Choose one of the divisors of the integer ai, i.e., an integer x such that aimodx=0;
  3. Replace ai with aix and aj with ajx.

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 a3=50 and a2=2, x=5. Replace a3 with a3x=505=10, and a2 with a2x=25=10. The resulting array is a = [100,10,10,10,1];
  2. Choose a1=100 and a5=1, x=10. Replace a1 with a1x=10010=10, and a5 with a5x=110=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 (1t2000) — 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 (1n104) — the number of elements in the array a.

The second line of each test case contains exactly n integers ai (1ai106) — the elements of the array a.

It is guaranteed that the sum of n over all test cases does not exceed 104.


B 1300

You have n sets of integers S1,S2,,Sn. We call a set S attainable, if it is possible to choose some (possibly, none) of the sets S1,S2,,Sn so that S is equal to their union. If you choose none of S1,S2,,Sn, their union is an empty set.

Find the maximum number of elements in an attainable S such that SS1S2Sn.

The union of sets A1,A2,,Ak is defined as the set of elements present in at least one of these sets. It is denoted by A1A2Ak. For example, {2,4,6}{2,3}{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 (1t100). The description of the test cases follows.

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

The following n lines describe the sets S1,S2,,Sn. The i-th of these lines contains an integer ki (1ki50) — the number of elements in Si, followed by ki integers si,1,si,2,,si,ki (1si,1<si,2<<si,ki50) — the elements of Si.



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

  • 数学+思维/入手点


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 @   Jkke  阅读(5)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
点击右上角即可分享
微信分享提示