Codeforces Round 945 (Div. 2) A - D

 

Codeforces Round 945 (Div. 2) A - D题_哔哩哔哩_bilibili

讲解都在视频里哦

A - Chess For Three

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int T;
    cin >> T;
    while (T--)
    {
        int p1, p2, p3;
        cin >> p1 >> p2 >> p3;
        vector<int> a({p1, p2, p3});
        if ((p1 + p2 + p3) % 2 != 0)
            cout << -1 << endl;
        else
        {
            int cnt = 0;
            while ((a[0] != 0 || a[1] != 0) && a[2] != 0)
            {
                a[2]--, a[1]--, cnt++;
                sort(a.begin(), a.end());
            }
            cout << cnt << endl;
        }
    }
    return 0;
}

B - Cat, Fox and the Lonely Array

#include <bits/stdc++.h>
using namespace std;

int main()
{
    int T;
    cin >> T;
    while (T--)
    {
        int n;
        cin >> n;
        vector<int> a(n);
        for (auto& i : a)
            cin >> i;
        int finalAns = 1;
        for (int i = 0; i <= 20; i++)
        {
            int cnt = 0, flag = 0;
            int ans = 1;
            for (auto j : a)
            {
                int dig = (j >> i) % 2;
                if (dig == 0)
                    cnt++;
                else
                    ans = max(ans, cnt + 1), cnt = 0, flag = 1;
            }
            if (cnt && flag)
                ans = max(ans, cnt + 1);
            finalAns = max(finalAns, ans);
        }
        cout << finalAns << endl;
    }
    cin.get();
    cin.get();
    return 0;
}

C - Cat, Fox and Double Maximum

#include <bits/stdc++.h>
using namespace std;

int main()
{
    int T;
    cin >> T;
    while (T--)
    {
        int n, dig, cnt = 0;
        cin >> n;
        vector<int> a(n);
        set<int> notChosen, chosen;
        queue<int> allocation;
        bool flag = true;
        for (int i = 0; i < n; i++)
        {
            cin >> dig;
            a[i] = dig;
            allocation.push(n - i);
            if (dig == 1 && i % 2 != 0 && i != n - 1)
                flag = false;
        }
        if (flag)
            for (int i = 0; i < n; i++)
                if (i % 2 != 0 && i != n - 1)
                    chosen.insert(a[i]);
                else
                    notChosen.insert(a[i]);
        else
            for (int i = 0; i < n; i++)
                if (i % 2 == 0 && i != 0)
                    chosen.insert(a[i]);
                else
                    notChosen.insert(a[i]);
        map<int, int> M;
        for (auto i : chosen)
            M[i] = allocation.front(), allocation.pop();
        for (auto i : notChosen)
            M[i] = allocation.front(), allocation.pop();
        for (auto i : a)
            cout << M[i] << ' ';
        cout << endl;
    }
    return 0;
}

D - Cat, Fox and Maximum Array Split

#include <bits/stdc++.h>
using namespace std;

int main()
{
    int T;
    cin >> T;
    while (T--)
    {
        int n, k, dig, maxNum;
        cin >> n >> k;
        for (int i = 1; i <= n; i++)
        {
            cout << "? " << 1 << ' ' << i * n << endl;
            cin >> dig;
            if (dig == n)
                maxNum = i;
        }
        int m = -1;
        for (int i = 1; i <= n / k; i++)
        {
            int l = 1, time = k;
            while (l <= n && time--)
            {
                cout << "? " << l << ' ' << i * maxNum << endl;
                cin >> dig;
                if (dig == n + 1)
                    break;
                l = dig + 1;
            }
            if (l == n + 1 && time == 0)
            {
                m = maxNum * i;
                break;
            }
        }
        cout << "! " << m << endl;
        cin >> dig;
    }
    return 0;
}

  • 4
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
抱歉,根据提供的引用内容,我无法理解你具体想要问什么问题。请提供更清晰明确的问题,我将竭诚为你解答。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [Codeforces Round 860 (Div. 2)题解](https://blog.csdn.net/qq_60653991/article/details/129802687)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [【CodeforcesCodeforces Round 865 (Div. 2) (补赛)](https://blog.csdn.net/t_mod/article/details/130104033)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [Codeforces Round 872 (Div. 2)(前三道](https://blog.csdn.net/qq_68286180/article/details/130570952)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值