2024.12.11 周三

2024.12.11 周三


Q1. 1100

给定一长度为 n 的数组,你需要执行 k 次操作:每次选择一连续子数组(可为空),将和作为一元素放到到数组的任意位置。问最后数组和的最大值。

Q2. 1100

给你一长度为2n的数组a1~n各出现2次。让你找出两个大小为2k集合l,r,其中l属于a1anr属于an+1a2n。满足l异或和等于r异或和。

Q3. 1000

Rudolf has an array a of n integers.
In one operation, he can choose an index i (2in1) and assign:

  • ai1=ai11
  • ai=ai2
  • ai+1=ai+11

Rudolf can apply this operation any number of times. Any index i can be used zero or more times.

Can he make all the elements of the array equal to zero using this operation?

Q4. 1100

给你一长度为n的数组,x为0,i:1~n,找到大于x且为ai倍数的数,更新x

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

A1. 2点

1.第一次操作必然是选择最大连续子数组,然后将其放到最大连续子数组内。

2.以后的操作就可以看作最大和一变二,二变四的过程。

A2. 2点

1.发现a1an这一侧单独出现的数字与右侧相同。

2.同时出现2次的数异或和为0。可以先使用出现2次的数构造,不够再使用单次出现的数构造。

A3. 1点

1.遍历贪心去减,不够减/最后没减为0则NO

A4. 2点

1.快速找到大于xai的倍数,直接枚举显然不可行。二分当然可以。

2.数学当然ok,kai>x,=>k>=x/ai,==>k=x/ai+1,取整的时候注意一下,答案就是kai

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

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;
}
const int mod = 1e9 + 7;
int qm(int a, int b)
{
    int res = 1;
    while (b)
    {
        if (b & 1)
            res = res * a % mod; // 不要取模时记得取消
        a = a * a % mod;
        b >>= 1;
    }
    return res;
}
int inv(int n)
{
    return qm(n, mod - 2);
}

void _()
{
    int n, k;
    cin >> n >> k;
    int pre = 0, min_pre = 0, max_rangesum = 0;
    for (int i = 0; i < n; i++)
    {
        int x;
        cin >> x;
        pre += x;
        max_rangesum = max(max_rangesum, pre - min_pre);
        min_pre = min(min_pre, pre);
    }
    int res = (max_rangesum % mod * qm(2, k)) % mod;
    res = (res + pre % mod - max_rangesum % mod + (int)(1e7) * mod) % mod;
    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, k;
    cin >> n >> k;
    vector<int> l(n + 1);
    for (int i = 0; i < n; i++)
    {
        int x;
        cin >> x;
        l[x]++;
    }
    for (int i = 0; i < n; i++)
    {
        int x;
        cin >> x;
    }
    set<int> db_l, db_r, sgal;
    for (int i = 1; i <= n; i++)
        if (!l[i])
            db_r.insert(i);
        else if (l[i] == 1)
            sgal.insert(i);
        else
            db_l.insert(i);
    vector<int> res_l, res_r;
    auto get = [&](vector<int> &res, set<int> &l)
    {
        for (auto x : l)
            if (res.size() < k << 1)
                res.push_back(x), res.push_back(x);
        for (auto x : sgal)
            if (res.size() < k << 1)
                res.push_back(x);
    };
    get(res_l, db_l);
    get(res_r, db_r);
    for (auto v : res_l)
        cout << v << ' ';
    cout << endl;
    for (auto v : res_r)
        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;
    vector<int> a(n + 1);
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    int f = 1;
    for (int i = 1; i + 2 <= n; i++)
    {
        if (a[i + 1] < a[i] << 1 || a[i + 2] < a[i])
            f = 0;
        a[i + 1] -= a[i] << 1;
        a[i + 2] -= a[i];
    }
    if (a[n - 1] || a[n])
        f = 0;
    cout << (f ? "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 n;
    cin >> n;
    int x;
    cin >> x;
    int res = x;
    for (int i = 2; i <= n; i++)
    {
        cin >> x;
        int k = res / x + 1;
        res = x * k;
    }
    cout << res << endl;
}
posted @   Jkke  阅读(2)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
点击右上角即可分享
微信分享提示