首页 > 其他分享 >2024.12.12 周四

2024.12.12 周四

时间:2024-12-13 12:20:29浏览次数:11  
标签:2024.12 周四 12 string int cin long ++ define

2024.12.12 周四


Q1. 1000

You have an array $a$ of $n$ integers.

You can no more than once apply the following operation: select three integers $i$, $j$, $x$ ($1 \le i \le j \le n$) and assign all elements of the array with indexes from $i$ to $j$ the value $x$. The price of this operation depends on the selected indices and is equal to $(j - i + 1)$ burles.
What is the least amount of burles you need to spend to make all the elements of the array equal?

Q2. 1000

You are given a positive integer $n$.

Find a permutation$^\dagger$ $p$ of length $n$ such that there do not exist two distinct indices $i$ and $j$ such that $p_i$ divides $p_j$ and $p_{i+1}$ divides $p_{j+1}$.

Under the constraints of this problem, it can be proven that at least one $p$ exists.

Q3. 1000

Given an array $a$ of $n$ integers, an array $b$ of $m$ integers, and an even number $k$.

Your task is to determine whether it is possible to choose exactly $\frac{k}{2}$ elements from both arrays in such a way that among the chosen elements, every integer from $1$ to $k$ is included.

Q4. 1000

A certain number $1 \le x \le 10^9$ is chosen. You are given two integers $a$ and $b$, which are the two largest divisors of the number $x$. At the same time, the condition $1<=a<b<x$ is satisfied.

For the given numbers $a$, $b$, you need to find the value of $x$.

Q5. 1000

You are given a binary string $s$.

You can perform two types of operations on $s$:

  1. delete one character from $s$. This operation costs $1$ coin;
  2. swap any pair of characters in $s$. This operation is free (costs $0$ coins).

You can perform these operations any number of times and in any order.

Let's name a string you've got after performing operations above as $t$. The string $t$ is good if for each $i$ from $1$ to $|t|$ $t_i \neq s_i$ ($|t|$ is the length of the string $t$). The empty string is always good. Note that you are comparing the resulting string $t$ with the initial string $s$.

What is the minimum total cost to make the string $t$ good?

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

  • Q2构造 Q4数论 比较有意思

A1.

  1. 发现只有3种情况,找边界枚举即可。

A2.

  1. 倍数就一定相差至少一倍。
  2. 如何构造使相邻的2个数都无法找到倍数,1~n存在一半的数无法找到其倍数,因此考虑存在倍数与不存在倍数的数相邻。如:1 n 2 n-1 3 n-2...

A3.

  1. 变量维护两数组选的数的个数,map维护两数组有的数。
  2. 遍历1~k:考虑独有的,直接加入,若不能加入/都没有则无解。共有的不需要考虑,因为只要二者选的数次数满足,最后一定可以满足。

A4.

  1. 对 $x$ 因式分解,b=x/p1,a=x/p1 $or$ x/p2,...嗯..是道好题。

A5.

  1. 任意交换代表任意安排,贪心从前向后构造,直到不能构造,删除剩下的。

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

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 n;
    cin >> n;
    vector<int> a(n + 1);
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    int res = n;
    int l = 1;
    for (; l + 1 <= n && a[l + 1] == a[1]; l++)
        ;
    res = min(res, n - l);
    int r = n;
    for (; r > 1 && a[r - 1] == a[n]; r--)
        ;
    res = min(res, r - 1);
    if (a[1] == a[n])
    {
        if (l >= r)
            res = 0;
        else
            res = min(res, r - l - 1);
    }
    cout << res << 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 n;
    cin >> n;
    int l = 1, r = n;
    int f = 1;
    while (l <= r)
    {
        if (f)
            cout << l << ' ', l++;
        else
            cout << r << ' ', r--;
        f ^= 1;
    }
    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, m, k;
    cin >> n >> m >> k;
    map<int, int> ka, kb;
    for (int i = 0; i < n; i++)
    {
        int x;
        cin >> x;
        ka[x] = 1;
    }
    for (int i = 0; i < m; i++)
    {
        int x;
        cin >> x;
        kb[x] = 1;
    }
    bool ans = 1;
    int cnta = 0, cntb = 0;
    for (int i = 1; i <= k; i++)
        if (ka[i] + kb[i] == 1)
        {
            int f = 0;
            if (ka[i] && cnta < k / 2)
                cnta++, f = 1;
            if (kb[i] && cntb < k / 2)
                f = 1, cntb++;
            if (!f)
                ans = f;
        }
        else if (ka[i] + kb[i] == 0)
            ans = 0;

    cout << (ans ? "YES" : "NO") << endl;
}
// void _()
// {
//     int n, m, k;
//     cin >> n >> m >> k;
//     map<int, int> ka, kb;
//     for (int i = 0; i < n; i++)
//     {
//         int x;
//         cin >> x;
//         ka[x]++;
//     }
//     for (int i = 0; i < m; i++)
//     {
//         int x;
//         cin >> x;
//         kb[x]++;
//     }
//     set<int> K;
//     int cnta = 0, cntb = 0;
//     for (int i = 1; i <= k; i++)
//         if (ka[i] + kb[i] == 1)
//         {
//             if (ka[i] && cnta < k / 2)
//                 K.insert(i), cnta++;
//             if (kb[i] && cntb < k / 2)
//                 K.insert(i), cntb++;
//         }
//     for (int i = 1; i <= k; i++)
//         if (ka[i] + kb[i] > 1)
//         {
//             if (cnta < k / 2)
//             {
//                 if (ka[i])
//                 {
//                     K.insert(i), cnta++;
//                     continue;
//                 }
//             }
//             if (cntb < k / 2)
//             {
//                 if (kb[i])
//                 {
//                     K.insert(i), cntb++;
//                     continue;
//                 }
//             }
//         }
//     cout << (K.size() == k ? "YES" : "NO") << endl;
// }

A4.

#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 a, b;
    cin >> a >> b;
    auto get = [](int n)
    {
        for (int i = 2; i <= n / i; i++)
            if (n % i == 0)
                return i;
        return n;
    };
    int res = b * b / a;
    if (b % a)
        res = b * get(a);
    cout << res << endl;
}

A5

#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 _()
{
    string s;
    cin >> s;
    int n = s.size();
    s = " " + s;
    int cnt0 = 0;
    for (int i = 1; i <= n; i++)
        cnt0 += s[i] == '0';
    int cnt1 = n - cnt0;
    int res = 0;
    // bug2(cnt0, cnt1);
    for (int i = 1; i <= n; i++)
    {
        if (s[i] == '0')
        {
            if (!cnt1)
            {
                res = n - (i - 1);
                break;
            }
            cnt1--;
        }
        else
        {
            if (!cnt0)
            {
                res = n - (i - 1);
                break;
            }
            cnt0--;
        }
    }
    cout << res << endl;
}

标签:2024.12,周四,12,string,int,cin,long,++,define
From: https://www.cnblogs.com/jkkk/p/18604658

相关文章

  • 搜索广告召回技术在美团的实践12
      美团搜索广告介绍从美团流量场景角度来看,美团搜索广告分为两大类,一是列表推荐广告;二是搜索广告。推荐广告以展现商家模式为主,通常叫商家流。搜索广告的展现形式比较丰富,有商家模式,即以商家展现为主,会挂上菜品/商品;还有商品模式,即以商品展现为主,以呈现商品大图、商品标题等......
  • 【每日一题】20241213
    【每日一题】伽利略曾设计如图\(1\)所示的一个实验,将摆球拉至\(M\)点放开,摆球会达到同一水平高度上的\(N\)点.如果在\(E\)或\(F\)处钉子,摆球将沿不同的圆弧达到同一高度的对应点;反过来,如果计摆球从这些点下落,它同样会达到原水平高度上的\(M\)点.这个实验可以说明,物体......
  • 12.11日报
    今天完成软件设计实验二十四模板方法模式,以下为今日实验内容:实验24:模板方法模式本次实验属于模仿型实验,通过本次实验学生将掌握以下内容:1、理解模板方法模式的动机,掌握该模式的结构;2、能够利用模板方法模式解决实际问题。     [实验任务一]:数据库连接对......
  • 12.12日报
    今天完成机器学习B实验,并且进行软件需求分析大作业验收,以下为今日实验部分内容实验五:BP神经网络算法实现与测试一、实验目的深入理解支持向量机(SVM)的算法原理,能够使用Python语言实现支持向量机的训练与测试,并且使用五折交叉验证算法进行模型训练与评估。  二、实验内......
  • 【原创学习笔记】西门子1200 PLC如何实现伺服控制
    一、实现的功能及应用的场合通过PLC的不同指令,发送指令控制电机的启停和速度大小二、硬件配置1、西门子1214PLC2.TIAV163.SINAMICSG120C三、实现功能步骤1.添加设备G120CPN-调整以太网地址根据实际情况选择有无滤波器,电机参数,有无电机抱闸,最后完成调试向导......
  • 12.6日报
    今天完成软件构造实验以及软件企业文化的论文,以下为实验内容,Flash动画的编写:<template><div><!--顶部导航栏--><divstyle="height:60px;background-color:#fff;display:flex;align-items:center;border-bottom:1pxsolid#ddd"><......
  • 12.2日报
    今天完成软件设计实验二十一观察者模式,并且进一步学习了画数据流图,功能架构图实验21:观察者模式本次实验属于模仿型实验,通过本次实验学生将掌握以下内容:1、理解观察者模式的动机,掌握该模式的结构;2、能够利用观察者模式解决实际问题。     [实验任务一]:股......
  • 12.4日报
    完成机器学习B实验,以下为今日实验内容:实验四:SMO算法实现与测试一、实验目的深入理解支持向量机(SVM)的算法原理,能够使用Python语言实现支持向量机的训练与测试,并且使用五折交叉验证算法进行模型训练与评估。二、实验内容(1)从scikit-learn库中加载iris数据集,使用留出法留......
  • 12.5日报
    今天完成软件设计实验二十二状态模式,以下为实验内容:实验22:状态模式本次实验属于模仿型实验,通过本次实验学生将掌握以下内容:1、理解状态模式的动机,掌握该模式的结构;2、能够利用状态模式解决实际问题。     [实验任务一]:银行账户用Java代码模拟实现课堂上......
  • 94、基于AT89C52的OLED12832I2C液晶应用proteus仿真设计
    一、仿真原理图:二、仿真效果:三、相关代码:1、主函数:**************************************************************************************/voidmain(void){             SystemInit();   VariableInit();      OLED12832I2C......