2025.1.20——1300

2025.1.20——1300


A 1300

You are given a binary string s. A binary string is a string consisting of characters 0 and/or 1.

You can perform the following operation on s any number of times (even zero):

  • choose an integer i such that 1i|s|, then erase the character si.

You have to make s alternating, i. e. after you perform the operations, every two adjacent characters in s should be different.

Your goal is to calculate two values:

  • the minimum number of operations required to make s alternating;
  • the number of different shortest sequences of operations that make s alternating. Two sequences of operations are different if in at least one operation, the chosen integer i is different in these two sequences.

Input

The first line contains one integer t (1t104) — the number of test cases.

Each test case consists of one line containing the string s (1|s|2105). The string s consists of characters 0 and/or 1 only.

Additional constraint on the input:

  • the total length of strings s over all test cases does not exceed 2105.

B 1300

You are given two integers n and k. You are also given an array of integers a1,a2,,an of size n. It is known that for all 1in, 1aik.

Define a two-dimensional array b of size n×n as follows: bi,j=min(ai,aj). Represent array b as a square, where the upper left cell is b1,1, rows are numbered from top to bottom from 1 to n, and columns are numbered from left to right from 1 to n. Let the color of a cell be the number written in it (for a cell with coordinates (i,j), this is bi,j).

For each color from 1 to k, find the smallest rectangle in the array b containing all cells of this color. Output the sum of width and height of this rectangle.
Input

The first line contains a single integer t (1t104) — the number of test cases. Then follows the description of the test cases.

The first line of each test case contains two integers n and k (1n,k105) — the size of array a and the number of colors.

The second line of each test case contains n integers a1,a2,,an (1aik) — the array a.

It is guaranteed that the sum of the values of n and k over all test cases does not exceed 105.


C 1300

There is an empty matrix M of size n×m.

Zhongkao examination is over, and Daniel would like to do some puzzle games. He is going to fill in the matrix M using permutations of length m. That is, each row of M must be a permutation of length m.

Define the value of the i-th column in M as vi=MEX(M1,i,M2,i,,Mn,i). Since Daniel likes diversity, the beauty of M is s=MEX(v1,v2,,vm).

You have to help Daniel fill in the matrix M and maximize its beauty.

A permutation of length m is an array consisting of m distinct integers from 0 to m1 in arbitrary order. For example, [1,2,0,4,3] is a permutation, but [0,1,1] is not a permutation (1 appears twice in the array), and [0,1,3] is also not a permutation (m1=2 but there is 3 in the array).

The MEX of an array is the smallest non-negative integer that does not belong to the array. For example, MEX(2,2,1)=0 because 0 does not belong to the array, and MEX(0,3,1,2)=4 because 0, 1, 2 and 3 appear in the array, but 4 does not.
Input

The first line of input contains a single integer t (1t1000) — the number of test cases. The description of test cases follows.

The only line of each test case contains two integers n and m (1n,m2105) — the size of the matrix.

It is guaranteed that the sum of nm over all test cases does not exceed 2105.


D 1300

This is an interactive problem!

salyg1n gave Alice a set S of n distinct integers s1,s2,,sn (0si109). Alice decided to play a game with this set against Bob. The rules of the game are as follows:

  • Players take turns, with Alice going first.

  • In one move, Alice adds one number x (0x109) to the set S. The set S must not contain the number x at the time of the move.

  • In one move, Bob removes one number y from the set S. The set S must contain the number y at the time of the move. Additionally, the number y must be strictly smaller than the last number added by Alice.

  • The game ends when Bob cannot make a move or after 2n+1 moves (in which case Alice's move will be the last one).

  • The result of the game is MEX(S) (S at the end of the game).

  • Alice aims to maximize the result, while Bob aims to minimize it.

Let R be the result when both players play optimally. In this problem, you play as Alice against the jury program playing as Bob. Your task is to implement a strategy for Alice such that the result of the game is always at least R.

MEX of a set of integers c1,c2,,ck is defined as the smallest non-negative integer x which does not occur in the set c. For example, MEX({0,1,2,4}) = 3.


E 1300

Given two arrays a and b, both of length n. Elements of both arrays indexed from 1 to n. You are constructing a directed graph, where edge from u to v (uv) exists if auavbubv.

A vertex V is called strong if there exists a path from V to all other vertices.

A path in a directed graph is a chain of several vertices, connected by edges, such that moving from the vertex u, along the directions of the edges, the vertex v can be reached.

Your task is to find all strong vertices.

For example, if a=[3,1,2,4] and b=[4,3,2,1], the graph will look like this:

The graph has only one strong vertex with number 4
Input

The first line contains an integer t (1t104) — the number of test cases.

The first line of each test case contains an integer n (2n2105) — the length of a and b.

The second line of each test case contains n integers a1,a2an (109ai109) — the array a.

The third line of each test case contains n integers b1,b2bn (109bi109) — the array b.

It is guaranteed that the sum of n for all test cases does not exceed 2105.


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

  • 方案数/组合数学+发现结论/优化+MEX构造+交互博弈+guess。


A

  1. 难点在计算方案数,抽象了半天发现通过模拟可以得出计算方法。

B

  1. 模拟一下发现结论:本质是对 1~k 找到两侧边界开始大于其的第一个位置。
  2. 前缀维护最大值,二分可以快速回答。 但是考虑 1~k 单调性询问,发现可以双指针解决。

C

  1. 构造方式比较好想,再计算即可。

D

  1. 交互。模拟博弈过程,从答案值域和小数据下界入手。发现结论。

E

  1. 第一眼从样例猜出了答案。细想证明确实比较巧妙。

------------------------代码------------------------

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;
}

constexpr int mod = 998244353;
void _()
{
    string s;
    cin >> s;
    int n = s.size();
    s = " " + s;
    vector<int> len;
    for (int i = 1; i <= n; i++)
    {
        int j = i;
        for (; j <= n && s[j] == s[i]; j++) // j停在的位置为第一个不合法的地方
            ;
        len.push_back(j - i);
        i = j - 1;
    }
    auto get = [](int len)
    {
        int ans = 1;
        for (int i = 1; i <= len; i++)
            ans = ans * i % mod;
        return ans;
    };
    int res = 0, f = 1, t = 0;
    for (auto len : len)
        res += len - 1, f = f * len % mod, t += len - 1;
    f = f * get(t) % mod;
    cout << res << ' ' << f;
    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 (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, k;
    cin >> n >> k;
    vector<int> a(n + 1);
    vector<int> color(k + 1);
    for (int i = 1; i <= n; i++)
    {
        int x;
        cin >> x;
        a[i] = x;
        color[x] = 1;
    }
    int f = 1, g = n;
    for (int i = 1; i <= k; i++)
    {
        if (!color[i])
        {
            cout << 0 << ' ';
            continue;
        }
        int l = n;
        for (;; f++)
            if (a[f] >= i)
                break;
        ;
        for (;; g--)
            if (a[g] >= i)
                break;
        ;
        // bug3(i, f, g);
        cout << (g - f + 1 << 1) << ' ';
    }
    el;
}

C

#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, m;
    cin >> n >> m;
    vector<vector<int>> f(n + 1, vector<int>(m + 1));
    for (int j = 1; j <= m; j++)
        f[1][j] = j - 1;
    for (int i = 2; i <= min(n, m - 1); i++)
    {
        f[i][1] = f[i - 1][m];
        for (int j = 2; j <= m; j++)
            f[i][j] = f[i - 1][j - 1];
    }
    for (int i = m; i <= n; i++)
        for (int j = 1; j <= m; j++)
            f[i][j] = f[i - 1][j];
    auto MEX = [](vector<int> a)
    {
        sort(a.begin(), a.end());
        a.erase(unique(a.begin(), a.end()), a.end());
        for (int i = 0; i < a.size(); i++)
            if (a[i] - i)
                return i;
        return a.back() + 1;
    };
    vector<int> t;
    for (int j = 1; j <= m; j++)
    {
        vector<int> a;
        for (int i = 1; i <= n; i++)
            a.push_back(f[i][j]);
        t.push_back(MEX(a));
    }
    // bugv(t, 0);
    cout << MEX(t);
    el;
    for (int i = 1; i <= n; i++)
        bugv(f[i], 1);
}

D

#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, bool> has;
    for (int i = 0; i < n; i++)
    {
        int x;
        cin >> x;
        has[x] = 1;
    }
    auto f = [](int x)
    {
        cout << x << endl;
        cin >> x;
        return x;
    };
    if (!has[0])
    {
        f(0);
        return;
    }
    int ans = 0;
    for (;; ans++)
        if (!has[ans])
            break;

    int x = f(ans);
    while (~x)
        x = f(x);
}

E

#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;
    vector<int> f(n);
    for (int &x : f)
        cin >> x;
    int mx = -1e10;
    for (int i = 0; i < n; i++)
    {
        int x;
        cin >> x;
        f[i] -= x;
        mx = max(mx, f[i]);
    }
    int cnt = 0;
    vector<int> res;
    for (int i = 0; i < n; i++)
        if (f[i] == mx)
            cnt++, res.push_back(i + 1);
    cout << cnt;
    el;
    bugv(res, 0);
}

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