Codeforces Round 958 (Div. 2)解题报告(A-C)

A. Split the Multiset

题目大意:问通过几次操作可将集合的一个n值分为n个值为1的集合,没次操作可分为k份(PS:我理解成每次分成的小份值最大为k了,看了题解才做出来)

解题思路:每次拆分成k-1个1和1个值s-k-1(s为上一个非1zhi),可以得到最多需要 (n-1+k+2)/(k-1) 次(需考虑s-k-1为1的情况)

个人代码:

#include <bits/stdc++.h>

using namespace std;

void solve() {
    int n, k;
    cin >> n >> k;
    int c = (n-1 + k-2)/(k-1); //如果余数为一,不用再次切割
    cout << c << endl;
}

int main() {
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}

题解代码(Python):

t = (int)(input())
for _ in range(t):
    n, k = map(int, input().split())
    print((n - 1 + k - 2) // (k - 1))

B. Make Majority

题目大意:给你一个01序列,问通过相关操作能否得到序列[1]

解题思路:找到连续的0序列消为一个[0]序列,然后判断余下序列中1是否多于0

个人代码:

#include <bits/stdc++.h>

using namespace std;

void solve() {
    int n;
    cin >> n;
    string a;
    cin >> a;
    int zero, one;
    int flag = 0;
    zero = one = 0;
    for (int i = 0; i < a.size(); i++) {
        if (a[i] == '0' && !flag) {
            zero++;
            flag = 1;
        } else if (a[i] == '1') {
            flag = 0;
            one++;
        }
    }
    if (n == 1) {
        zero = one = 0;
        if (a[0] == '1') {
            one++;
        } else {
            zero++;
        }
    }
    if (one > zero) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

int main() {
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}

 题解代码(Python):

t = (int)(input())
for _ in range(t):
    n = (int)(input())
    a = input()
    ok = 0
    if a.count("111") >= 1:
        ok = 1
    if a.count("11") >= 2:
        ok = 1
    if a.count("11") >= 1 and (a[0] == "1" or a[-1] == "1"):
        ok = 1
    if a[0] == "1" and a[-1] == "1":
        ok = 1
    if ok:
        print("Yes")
    else:
        print("No")

C. Increasing Sequence with Fixed OR

题目大意:给一个数字n,问你能否找出一个长度为k的序列满足a[i] | a[i+1] = n (|为逻辑算法中的或)

解题思路:找到n的二进制中的1,按顺序依次将其中的1变为0

题解代码(Python):

t = (int)(input())
for _ in range(t):
    n = (int)(input())
    a = []
    for i in range(62, -1, -1):
        x = 1 << i
        if ((x & n) == x) and (x != n):
            a.append(n - x)
    a.append(n)
    print(len(a))
    for i in a:
        print(i, end=" ")
    print("")



c题带图解析

找到个别人的优秀解析,个人代码就是在此基础上添加注释

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

余额充值