Codeforces Round 948 (Div. 2) A - C

 

Codeforces Round 948 (Div. 2) A - C题_哔哩哔哩_bilibili

 讲解都在视频里哦

A - Little Nikita

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

int main()
{
    int T;
    cin >> T;
    while (T--)
    {
        int n, m;
        cin >> n >> m;
        if ((n - m) >= 0 && (n - m) % 2 == 0)
            cout << "YES\n";
        else
            cout << "NO\n";
    }
}

B - Binary Colouring

#include <bits/stdc++.h>
using namespace std;
#define int long long
int upperLimit[33];
int square[33];

void init()
{
    int dig = 0;
    for (int i = 0; i < 32; i++)
    {
        if (dig == 0)
            dig = 1;
        else
            dig *= 2;
        square[i] = dig;
        int index = i;
        while (index >= 0)
            upperLimit[i] += square[index], index -= 2;
    }
}

int find(int x)
{
    int dig = 0;
    for (int i = 0; i < 32; i++)
    {
        if (dig == 0)
            dig = 1;
        else
            dig *= 2;
        if (dig * 2 > x)
            return i;
    }
    return -1;
}

signed main()
{
    init();
    int T;
    cin >> T;
    while (T--)
    {
        int x, operation = 1, maxLength = INT_MIN;
        cin >> x;
        vector<int> ans(33, 0);
        while (x > 0)
        {
            int index = find(x);
            if (x > upperLimit[index])
            {
                index++;
                x = square[index] - x;
                maxLength = max(maxLength, index + 1);
                ans[index] = operation;
                operation = operation == 1 ? -1 : 1;
            }
            else
            {
                x -= square[index];
                maxLength = max(maxLength, index + 1);
                ans[index] = operation;
            }
        }
        cout << maxLength << endl;
        for (int i = 0; i < maxLength; i++)
            cout << ans[i] << ' ';
        cout << endl;
    }
}

C - Nikita and LCM

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

inline int LCM(int a, int b)
{
    return a * b / __gcd(a, b);
}

int calculate(int lcm, vector<int> &a)
{
    int realLCM = 1, ans = 0;
    for (auto &i : a)
    {
        if (lcm % i == 0)
            ans++, realLCM = LCM(realLCM, i);
    }
    if (realLCM != lcm)
        return 0;
    return ans;
}

signed main()
{
    int T;
    cin >> T;
    while (T--)
    {
        int n, maxNum = INT_MIN, flag = false;
        cin >> n;
        vector<int> a(n);
        set<int> S;
        for (auto &i : a)
            cin >> i, maxNum = max(maxNum, i), S.insert(i);
        for (auto &i : a)
            if (maxNum % i != 0)
            {
                cout << n << endl, flag = true;
                break;
            }
        if (!flag)
        {
            int ans = 0;
            for (int i = 2; i <= sqrt(maxNum); i++)
            {
                if (maxNum % i != 0)
                    continue;
                int divisor = i, divisor2 = maxNum / divisor;
                if (!S.count(divisor))
                    ans = max(ans, calculate(divisor, a));
                if (!S.count(divisor2))
                    ans = max(ans, calculate(divisor2, a));
            }
            cout << ans << endl;
        }
    }
}

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 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、付费专栏及课程。

余额充值