2024.12.17 周二

2024.12.17 周二


Q1. 1000

Jonathan is fighting against minions. There are n of them with strengths a1,a2,,an.

Denote (l,r) as the group consisting of the vampires with indices from l to r. More formally, the strength level of the group (l,r) is defined as

f(l,r)=al&al+1&al+2&&ar.

Here, & denotes the bitwise AND operation.

Jonathan will divide the vampires into contiguous groups, such that each vampire is in exactly one group, and the sum of strengths of the groups is minimized. Among all ways to divide the vampires, he would like to find the way with the maximum number of groups.

Given the strengths of each of the n vampires, find the maximum number of groups among all possible ways to divide the vampires with the smallest sum of strengths.

Q2. 1000

You are given a positive integer n.

In this problem, the MEX of a collection of integers c1,c2,,ck is defined as the smallest positive integer x which does not occur in the collection c.

The primality of an array a1,,an is defined as the number of pairs (l,r) such that 1lrn and MEX(al,,ar) is a prime number.

Find any permutation of 1,2,,n with the maximum possible primality among all permutations of 1,2,,n.

Q3. 1000

The array [a1,a2,,ak] is beautiful if there exists an integer i[0,k1] such that the array [ai+1,ai+2,,ak1,ak,a1,a2,,ai] is sorted in non-descending order.

Note that any array consisting of zero elements or one element is beautiful.

You are given an array a, which is initially empty. You have to process q queries to it. During the i-th query, you will be given one integer xi, and you have to do the following:

  • if you can append the integer xi to the back of the array a so that the array a stays beautiful, you have to append it;
  • otherwise, do nothing.

After each query, report whether you appended the given integer xi, or not.

Q4. 1000

Dima Vatrushin is a math teacher at school. He was sent on vacation for n days for his good work. Dima has long dreamed of going to a ski resort, so he wants to allocate several consecutive days and go skiing. Since the vacation requires careful preparation, he will only go for at least k days.

You are given an array a containing the weather forecast at the resort. That is, on the i-th day, the temperature will be ai degrees.

Dima was born in Siberia, so he can go on vacation only if the temperature does not rise above q degrees throughout the vacation.

Unfortunately, Dima was so absorbed in abstract algebra that he forgot how to count. He asks you to help him and count the number of ways to choose vacation dates at the resort.

Q5, 1000

You are given a string s consisting of the characters 0, 1 and/or ?. Let's call it a pattern.

Let's say that the binary string (a string where each character is either 0 or 1) matches the pattern if you can replace each character ? with 0 or 1 (for each character, the choice is independent) so that the strings become equal. For example, 0010 matches ?01?, but 010 doesn't match 1??, ??, or ????.

Let's define the cost of the binary string as the minimum number of operations of the form "reverse an arbitrary contiguous substring of the string" required to sort the string in non-descending order.

You have to find a binary string with the minimum possible cost among those that match the given pattern. If there are multiple answers, print any of them.

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

  • Q1较难,Q2二十分钟,Q3wa3发,Q4Q5都是十分钟顺切。

A1.

  1. 昨天被卡了,这次花了半小时过了。是道好题,不得不说,做位运算主要靠运算符的性质进行思考,需要很熟悉操作符或者时刻想着它。
  2. 发现最小值一定是f(1,n),再考虑如何在最小值情况下分出最多的连续块。
  3. 如果最小值非0,设为1101,那么每个块的每个元素都必须含1101,不然 & 和不可能为1101。这样块和一定不会为1101。因此不能分块。
  4. 最小值为0的话,贪心去分 0 0 0 ..。考虑2点:1.不可能出现0 1 0的情况,2.不能正好分块,最后的一部分合并在最后一块即可。

A2.

  1. 1是特殊的数,如果一个集合不包含1必定无贡献,包含1并且无2一定有贡献,包含1 2不含3一定有贡献。
  2. 考虑 2... 1...3 ,则可以构造出的贡献左侧选择的方案数*右侧选择的方案数,若n+1不是质数则-1。
  3. 构造真是有依据地进行天马行空。

A3.

  1. 其实就是分类进行模拟,值域考虑不完善wa了3发

A4.

  1. 找到每个合法的连续子段,考虑双指针(注意细节),保存长度。
  2. 对于每个合法长度,等差数列公式求方案数。

A5

  1. 算是一道构造,只要不增加连续1的段数就不会增加代价,同时改1可能会连接减少段数。
  2. 讨论各种情况后发现,? 只需要复制前面的即可。

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

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 ans = a[1];
    for (int i = 2; i <= n; i++)
        ans &= a[i];
    if (ans)
    {
        cout << 1 << endl;
        return;
    }
    int res = 0;
    for (int i = 1; i <= n; i++)
    {
        int t = a[i];
        if (!t)
        {
            res++;
            continue;
        }
        int j = i + 1;
        for (; j <= n; j++)
        {
            t &= a[j];
            if (!t)
                break;
        }
        // bug(j);
        if (j <= n)
            res++, j++;
        i = j - 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;
    vector<int> l, r;
    if (n > 1)
        l.push_back(2);
    int f = 1;
    for (int i = 4; i <= n; i++)
        if (f)
            l.push_back(i), f ^= 1;
        else
            r.push_back(i), f ^= 1;
    l.push_back(1);
    if (n > 2)
        r.push_back(3);
    auto output = [](vector<int> &t)
    {
        for (auto v : t)
            cout << v << ' ';
    };
    output(l);
    output(r);
    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 = 0; i < n; i++)
        cin >> a[i];

    int pre = a[0], las = a[1];
    int f = pre > las;
    string res = "11";
    for (int i = 2; i < n; i++)
    {
        int x = a[i];
        bool has = 0;
        if (!f)
        {
            if (x >= las || x <= pre) // 这里不判断确实思路不够完善 考虑整个值域
            {
                has = 1;
                if (x < las)
                    f = 1;
            }
        }
        else if (x <= pre && x >= las)
            has = 1;
        res += has ? '1' : '0';
        if (has)
            las = x;
    }
    if (n == 1)
        res = '1';
    cout << res << 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, k, q;
    cin >> n >> k >> q;
    vector<int> a(n + 1);
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    vector<int> t;
    for (int i = 1; i <= n; i++)
        if (a[i] <= q)
        {
            int j = i;
            for (; j <= n && a[j] <= q; j++)
                ;
            t.push_back(j - i);
            i = j - 1;
        }
    auto get = [k](int x)
    {
        return x < k ? 0 : (x - k + 1) * (x - k + 2) >> 1;
    };
    int res = 0;
    for (auto v : t)
        res += get(v); //, bug(v);
    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;
    if (s.front() == '?')
        s[0] = '0';
    for (int i = 1; i < s.size(); i++)
        if (s[i] == '?')
            s[i] = s[i - 1];
    cout << s << endl;
}
posted @   Jkke  阅读(3)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
点击右上角即可分享
微信分享提示