2024.12.21 周六

2024.12.21 周六


Q1. 1000

Lottery "Three Sevens" was held for m m m days. On day i i i, n i n_i ni people with the numbers a i , 1 , ... , a i , n i a_{i, 1}, \ldots, a_{i, n_i} ai,1,...,ai,ni participated in the lottery.

It is known that in each of the m m m days, only one winner was selected from the lottery participants. The lottery winner on day i i i was not allowed to participate in the lottery in the days from i + 1 i+1 i+1 to m m m.

Unfortunately, the information about the lottery winners has been lost. You need to find any possible list of lottery winners on days from 1 1 1 to m m m or determine that no solution exists.


Q2. 1000

Kristina has a string s s s of length n n n, consisting only of lowercase and uppercase Latin letters. For each pair of lowercase letter and its matching uppercase letter, Kristina can get 1 1 1 burl. However, pairs of characters cannot overlap, so each character can only be in one pair.

For example, if she has the string s s s = "aAaaBACacbE", she can get a burl for the following character pairs:

  • s 1 s_1 s1 = "a" and s 2 s_2 s2 = "A"
  • s 4 s_4 s4 = "a" and s 6 s_6 s6 = "A"
  • s 5 s_5 s5 = "B" and s 10 s_{10} s10 = "b"
  • s 7 s_7 s7= "C" and s 9 s_9 s9 = "c"

Kristina wants to get more burles for her string, so she is going to perform no more than k k k operations on it. In one operation, she can:

  • either select the lowercase character s i s_i si ( 1 ≤ i ≤ n 1 \le i \le n 1≤i≤n) and make it uppercase.
  • or select uppercase character s i s_i si ( 1 ≤ i ≤ n 1 \le i \le n 1≤i≤n) and make it lowercase.

For example, when k k k = 2 and s s s = "aAaaBACacbE" it can perform one operation: choose s 3 s_3 s3 = "a" and make it uppercase. Then she will get another pair of s 3 s_3 s3 = "A" and s 8 s_8 s8 = "a"

Find maximum number of burles Kristina can get for her string.


Q3. 1000

You are given a two-dimensional plane, and you need to place n n n chips on it.

You can place a chip only at a point with integer coordinates. The cost of placing a chip at the point ( x , y ) (x, y) (x,y) is equal to ∣ x ∣ + ∣ y ∣ |x| + |y| ∣x∣+∣y∣ (where ∣ a ∣ |a| ∣a∣ is the absolute value of a a a).

The cost of placing n n n chips is equal to the maximum among the costs of each chip.

You need to place n n n chips on the plane in such a way that the Euclidean distance between each pair of chips is strictly greater than 1 1 1, and the cost is the minimum possible.

------------------------独自思考分割线------------------------

Q1 Q3有些意思。1000分的题先到这,位运算,构造,数论,三者最难。

A1.

  1. 发现制约关系:当前答案的数后面的数组都不能出现。从后向前扫,未标记的数就可以作为答案。
  2. 这是必要性,需要证明一下充分性。

A2.

  1. 本质就是大小写匹配的次数,剩下的自己匹配自己(需要代价)。
  2. 前一天扫描贪心匹配wa了,现在复习也没时间去找bug。先这样了

A3.

  1. 被卡住了 还有些疑问,去学vue写报告了,先这样

------------------------代码分割线------------------------

A1.

#include <bits/stdc++.h>
#define int long long //
#define endl '\n'     // 交互/调试 关
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
void _();
signed main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cout << fixed << setprecision(6);
    int T = 1;
    cin >> T;
    while (T--)
        _();
    return 0;
}

void _()
{
    int m;
    cin >> m;
    vector<vector<int>> a(m);
    vector<int> vis(50010);
    for (auto &v : a)
    {
        int n;
        cin >> n;
        while (n--)
        {
            int x;
            cin >> x;
            v.push_back(x);
        }
    }
    vector<int> res;
    for (int i = m - 1; i >= 0; i--)
    {
        auto v = a[i];
        int f = 0;
        for (auto t : v)
        {
            if (!vis[t] && !f)
            {
                f = 1;
                res.push_back(t);
            }
            vis[t] = 1;
        }
    }
    if (res.size() - m)
        res.assign(1, -1);
    reverse(res.begin(), res.end());

    for (auto v : res)
        cout << v << " ";
    cout << endl;
}

A2.

#include <bits/stdc++.h>
#define int long long //
#define endl '\n'     // 交互/调试 关
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
void _();
signed main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cout << fixed << setprecision(6);
    int T = 1;
    cin >> T;
    while (T--)
        _();
    return 0;
}

void _()
{
    int m;
    cin >> m;
    vector<vector<int>> a(m);
    vector<int> vis(50010);
    for (auto &v : a)
    {
        int n;
        cin >> n;
        while (n--)
        {
            int x;
            cin >> x;
            v.push_back(x);
        }
    }
    vector<int> res;
    for (int i = m - 1; i >= 0; i--)
    {
        auto v = a[i];
        int f = 0;
        for (auto t : v)
        {
            if (!vis[t] && !f)
            {
                f = 1;
                res.push_back(t);
            }
            vis[t] = 1;
        }
    }
    if (res.size() - m)
        res.assign(1, -1);
    reverse(res.begin(), res.end());

    for (auto v : res)
        cout << v << " ";
    cout << endl;
}

A3.

#include <bits/stdc++.h>
#define int long long //
#define endl '\n'     // 交互/调试 关
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
void _();
signed main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cout << fixed << setprecision(6);
    int T = 1;
    cin >> T;
    while (T--)
        _();
    return 0;
}

void _()
{
    int n;
    cin >> n;
    int res = ceil(sqrtl(n)) - 1;
    cout << res << endl;
}
// void _()
// {
//     int n;
//     cin >> n;
//     int qrt_n = sqrt(n);
//     int k = qrt_n / 2 + (qrt_n * qrt_n != n);
//     int res = k - 1 << 1 | 1;
//     if ((k - 1) * (k - 1) << 2 == n - 1)
//         res--;
//     if (n == 1)
//         res = 0;
//     // bug(k);
//     cout << res << endl;
// }
相关推荐
编程之路,妙趣横生1 小时前
list模拟实现
c++
88号技师3 小时前
2024年12月一区SCI-加权平均优化算法Weighted average algorithm-附Matlab免费代码
人工智能·算法·matlab·优化算法
IT猿手3 小时前
多目标应用(一):多目标麋鹿优化算法(MOEHO)求解10个工程应用,提供完整MATLAB代码
开发语言·人工智能·算法·机器学习·matlab
88号技师3 小时前
几款性能优秀的差分进化算法DE(SaDE、JADE,SHADE,LSHADE、LSHADE_SPACMA、LSHADE_EpSin)-附Matlab免费代码
开发语言·人工智能·算法·matlab·优化算法
一只小bit3 小时前
数据结构之栈,队列,树
c语言·开发语言·数据结构·c++
我要学编程(ಥ_ಥ)4 小时前
一文详解“二叉树中的深搜“在算法中的应用
java·数据结构·算法·leetcode·深度优先
埃菲尔铁塔_CV算法4 小时前
FTT变换Matlab代码解释及应用场景
算法
沐泽Mu5 小时前
嵌入式学习-QT-Day05
开发语言·c++·qt·学习
许野平5 小时前
Rust: enum 和 i32 的区别和互换
python·算法·rust·enum·i32
chenziang15 小时前
leetcode hot100 合并区间
算法