2024.12.1 周日

2024.12.1 周日


Q1. 1000

对于字符串p,对定义f(p):p的所有连续子串中去重后的数量。

给定字符串s,问其是否存在一个子串t满足f(t)为偶数。

Q2. 1200

给定一数组,操作:选择一区间[l,r],将此区间的所有数变成所有数的中位数。

问最终数组变成相同数的最大值。

Q3. 1300

给定p数组(1~n的排列)和a数组以及时间(<=1e9),每秒可获得a[i]分然后可选择移动到a[p[i]]处/不动。

2人分别在给定起点,问最优策略下最后分数大小。

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

A1.

思维

A2.

思维

A3.

最优策略一定是呆在某个点。找到环,枚举时间允许到的点贪心找最大。

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

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

//  4mins-14mins-18mins
void _()
{
    string s;
    cin >> s;
    for (int i = 0; i + 1 < s.size(); i++)
        if (s[i] == s[i + 1])
        {
            cout << s.substr(i, 2) << endl;
            return;
        }
    if (s.size() >= 3)
    {
        for (int i = 0; i + 2 < s.size(); i++)
            if (s[i] - s[i + 1] && s[i] - s[i + 2])
            {
                cout << s.substr(i, 3) << endl;
                return;
            }
    }
    cout << -1 << 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> a(n + 1);
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    int res = 0;
    for (int i = 1; i < n; i++)
        res = max(res, min(a[i], a[i + 1]));
    for (int i = 2; i < n; i++)
    {
        vector<int> vec{a[i - 1], a[i], a[i + 1]};
        sort(vec.begin(), vec.end());
        res = max(res, vec[1]);
    }
    cout << res << 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;
}

//  36mins
void _()
{
    int n, k, pb, ps;
    cin >> n >> k >> pb >> ps;
    vector<int> p(n + 1), a(n + 1);
    for (int i = 1; i <= n; i++)
        cin >> p[i];
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    auto get = [&](int st)
    {
        vector<int> ans;
        ans.push_back(0);
        int id = 0;
        int ne = st;
        while (1)
        {
            ans.push_back(a[ne]);
            ne = p[ne];
            if (ne == st)
                break;
        }
        int n = ans.size();
        for (int i = 1; i < n; i++)
            ans[i] += ans[i - 1];
        int maxw = 0;
        for (int i = 1; i < n; i++) // 1~n-1
            if (k >= i)
            {
                // bug2((ans[i] - ans[i - 1]), (k - i + 1));
                maxw = max(maxw, ans[i - 1] + (ans[i] - ans[i - 1]) * (k - i + 1));
            }
        return maxw;
    };
    int score_b = get(pb), score_s = get(ps);
    // bug2(score_b, score_s);
    if (score_b == score_s)
        cout << "Draw" << endl;
    else
        cout << (score_b > score_s ? "Bodya" : "Sasha") << endl;
}
posted @   Jkke  阅读(6)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
点击右上角即可分享
微信分享提示