2025.1.24——1400

2025.1.24——1400


A 1400

Two players are playing an online card game. The game is played using a 32-card deck. Each card has a suit and a rank. There are four suits: clubs, diamonds, hearts, and spades. We will encode them with characters 'C', 'D', 'H', and 'S', respectively. And there are 8 ranks, in increasing order: '2', '3', '4', '5', '6', '7', '8', '9'.

Each card is denoted by two letters: its rank and its suit. For example, the 8 of Hearts is denoted as 8H.

At the beginning of the game, one suit is chosen as the trump suit.

In each round, players make moves like this: the first player places one of his cards on the table, and the second player must beat this card with one of their cards. After that, both cards are moved to the discard pile.

A card can beat another card if both cards have the same suit and the first card has a higher rank than the second. For example, 8S can beat 4S. Additionally, a trump card can beat any non-trump card, regardless of the rank of the cards, for example, if the trump suit is clubs ('C'), then 3C can beat 9D. Note that trump cards can be beaten only by the trump cards of higher rank.

There were n rounds played in the game, so the discard pile now contains 2n cards. You want to reconstruct the rounds played in the game, but the cards in the discard pile are shuffled. Find any possible sequence of n rounds that might have been played in the game.
Input

The first line contains integer t (1t100) — the number of test cases. Then t test cases follow.

The first line of a test case contains the integer number n (1n16).

The second line of a test case contains one character, the trump suit. It is one of "CDHS".

The third line of a test case contains the description of 2n cards. Each card is described by a two-character string, the first character is the rank of the card, which is one of "23456789", and the second one is the suit of the card, which is one of "CDHS". All cards are different.


B 1400

You are given an array a of length n, a positive integer m, and a string of commands of length n. Each command is either the character 'L' or the character 'R'.

Process all n commands in the order they are written in the string s. Processing a command is done as follows:

  • First, output the remainder of the product of all elements of the array a when divided by m.
  • Then, if the command is 'L', remove the leftmost element from the array a, if the command is 'R', remove the rightmost element from the array a.

Note that after each move, the length of the array a decreases by 1, and after processing all commands, it will be empty.

Write a program that will process all commands in the order they are written in the string s (from left to right).
Input

The first line contains an integer t (1t104) — the number of test cases in the input. Then descriptions of t test cases follow.

Each test case of the input is given by three lines.

The first line contains two integers n and m (1n2105,1m104) — the initial length of the array a and the value to take the remainder by.

The second line contains n integers a1,a2,,an (1ai104) — the elements of the array a.

The third line contains a string s consisting of n characters 'L' and 'R'.

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


C 1400

Sasha gave Anna a list a of n integers for Valentine's Day. Anna doesn't need this list, so she suggests destroying it by playing a game.

Players take turns. Sasha is a gentleman, so he gives Anna the right to make the first move.

  • On her turn, Anna must choose an element ai from the list and reverse the sequence of its digits. For example, if Anna chose the element with a value of 42, it would become 24; if Anna chose the element with a value of 1580, it would become 851. Note that leading zeros are removed. After such a turn, the number of elements in the list does not change.
  • On his turn, Sasha must extract two elements ai and aj (ij) from the list, concatenate them in any order and insert the result back into the list. For example, if Sasha chose the elements equal to 2007 and 19, he would remove these two elements from the list and add the integer 200719 or 192007. After such a turn, the number of elements in the list decreases by 1.

Players can't skip turns. The game ends when Sasha can't make a move, i.e. after Anna's move there is exactly one number left in the list. If this integer is not less than 10m (i.e., 10m), Sasha wins. Otherwise, Anna wins.

It can be shown that the game will always end. Determine who will win if both players play optimally.
Input

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

Then follows the description of the test cases.

The first line of each test case contains integers n, m (1n2105, 0m2106) — the number of integers in the list and the parameter determining when Sasha wins.

The second line of each test case contains n integers a1,a2,,an (1ai109) — the list that Sasha gave to Anna.

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


D 1400

Sasha decided to give his girlfriend the best handbag, but unfortunately for Sasha, it is very expensive. Therefore, Sasha wants to earn it. After looking at earning tips on the internet, he decided to go to the casino.

Sasha knows that the casino operates under the following rules. If Sasha places a bet of y coins (where y is a positive integer), then in case of winning, he will receive yk coins (i.e., his number of coins will increase by y(k1)). And in case of losing, he will lose the entire bet amount (i.e., his number of coins will decrease by y).

Note that the bet amount must always be a positive (>0) integer and cannot exceed Sasha's current number of coins.

Sasha also knows that there is a promotion at the casino: he cannot lose more than x times in a row.

Initially, Sasha has a coins. He wonders whether he can place bets such that he is guaranteed to win any number of coins. In other words, is it true that for any integer n, Sasha can make bets so that for any outcome that does not contradict the rules described above, at some moment of time he will have at least n coins.
Input

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

The single line of each test case contains three integers k,x and a (2k30, 1x100, 1a109) — the number of times the bet is increased in case of a win, the maximum number of consecutive losses, and the initial number of coins Sasha has.


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

  • 模拟+思维+贪心/博弈+赌博(


A

  1. 模拟,唯一注意点就是 stl 和函数的使用可以使过程简化。

B

  1. 删除操作较难维护(需要线段树),逆向思维发现添加操作较易维护。

C

  1. 发现两人的操作本质都是保护/删除一个数后导0的个数。排序贪心。

D

  1. 这个有点灵光一现。当前局下注的筹码在获胜情况下可以把所有输的都赢回来,直到必胜局,判断原有筹码是否足够。注意循环下来可能爆long long,提前结束。

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

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

void _()
{
    int n;
    char op;
    set<string> C, D, H, S;
    cin >> n >> op;
    for (int i = 0; i < n << 1; i++)
    {
        string t;
        cin >> t;
        if (t[1] == 'C')
            C.insert(t);
        else if (t[1] == 'D')
            D.insert(t);
        else if (t[1] == 'H')
            H.insert(t);
        else
            S.insert(t);
    }
    vector<string> res;
    bool has = 1;
    auto f = [&](set<string> &mx, set<string> &a)
    {
        while (a.size())
        {
            res.push_back(*a.begin());
            a.erase(a.begin());
            if (a.size())
            {
                res.push_back(*a.begin());
                a.erase(a.begin());
            }
            else
            {
                if (mx.size())
                {
                    res.push_back(*mx.begin());
                    mx.erase(mx.begin());
                }
                else
                    has = 0;
            }
        }
    };
    auto get = [&](set<string> mx, set<string> a, set<string> b, set<string> c)
    {
        f(mx, a);
        f(mx, b);
        f(mx, c);
        while (mx.size())
        {
            res.push_back(*mx.begin());
            mx.erase(mx.begin());
        }
    };

    if (op == 'C')
        get(C, H, S, D);
    else if (op == 'D')
        get(D, C, H, S);
    else if (op == 'H')
        get(H, C, D, S);
    else if (op == 'S')
        get(S, C, H, D);
    if (!has)
    {
        cout << "IMPOSSIBLE";
        el;
        return;
    }

    for (int i = 0; i < n << 1; i += 2)
        cout << res[i] << ' ' << res[i + 1] << endl;
}

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, m;
    cin >> n >> m;
    vector<int> a(n + 1);
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    string s;
    cin >> s;

    int l = 1, r = n;
    for (int i = 0; i < n - 1; i++)
    {
        if (s[i] == 'L')
            l++;
        else
            r--;
    }

    int ans = a[l] % m;
    vector<int> res{ans};
    for (int i = n - 2; i >= 0; i--)
    {
        if (s[i] == 'L')
            l--, ans = ans * a[l] % m;
        else
            r++, ans = ans * a[r] % m;
        res.push_back(ans);
    }
    reverse(res.begin(), res.end());
    bugv(res, 0);
}
// void _()
// {
//     int n, m;
//     cin >> n >> m;
//     vector<int> a(n + 1);
//     for (int i = 1; i <= n; i++)
//         cin >> a[i];
//     string s;
//     cin >> s;
//     // ST表  RMQ  倍增
//     // 查询区间最大值   静态查询   线段树可以修改
//     // dp[i][j] 以i为起点 长度为1<<j的区间的最大值

//     vector<vector<int>> dp(n + 1, vector<int>(32)); // 内存超限 必要时关long long
//                                                     // init
//     for (int j = 0; j < 30; j++)                    // j 是每一层状态
//         for (int i = 1; i <= n; i++)
//         {
//             if (i + (1 << j) - 1 > n)
//                 continue;
//             if (!j)
//                 dp[i][j] = a[i];
//             else
//                 dp[i][j] = dp[i][j - 1] * dp[i + (1 << j - 1)][j - 1];
//         }

//     // query
//     auto ask = [&](int l, int r)
//     {
//         int k = log(r - l + 1) / log(2);
//         return dp[l][k] * dp[r + 1 - (1 << k)][k];
//     };
//     bugv(a, 1);
//     for (int i = 1; i <= n; i++)
//         for (int j = 1; j <= i; j++)
//             bug3(i, j, ask(i, j));
//     // int l, r;
//     // l = 1, r = n;
//     // for (int i = 0; i < n; i++)
//     // {
//     //     cout << ask(l, r) << ' ';
//     //     if (s[i] == 'L')
//     //         l++;
//     //     else
//     //         r++;
//     // }
//     // 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;
    int digs = 0;
    vector<int> dig_0s;
    auto cal = [&](int x)
    {
        int dig_0 = 0;
        bool zero = 1;
        while (x)
        {
            if (x % 10 == 0 && zero)
                dig_0++;
            else
                zero = 0;
            digs++;
            x /= 10;
        }
        dig_0s.push_back(dig_0);
    };
    for (int i = 0; i < n; i++)
    {
        int x;
        cin >> x;
        cal(x);
    }
    sort(dig_0s.rbegin(), dig_0s.rend());
    for (int i = 0; i < dig_0s.size(); i += 2)
        digs -= dig_0s[i];
    cout << (digs > m ? "Sasha" : "Anna");
    el;
}

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 k, x, a;
    cin >> k >> x >> a;
    int has = 0;
    for (int i = 1; i <= x + 1; i++)
    {
        int t = (has + k - 1) / (k - 1);
        // bug2(i, t);
        has += t;
        if (has > a)
        {
            cout << "NO";
            el;
            return;
        }
    }
    // bug(has);
    cout << (a >= has ? "YES" : "NO");
    el;
}

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