• AtCoder abc 136


    C
    从后向前贪心
    D
    寻找规律
    推一下可以发现连续的RR…RLL…L可以作为一个独立的循环节
    最后这个循环节内的数字集中在RL的交界处
    再处理一下奇偶性就好

    # -*- coding: utf-8 -*-
    # @time     : 2023/6/2 13:30
    # @author   : yhdu@tongwoo.cn
    # @desc     :
    # @file     : atcoder.py
    # @software : PyCharm
    import bisect
    import copy
    import sys
    from sortedcontainers import SortedList
    from collections import defaultdict, Counter, deque
    from functools import lru_cache, cmp_to_key
    import heapq
    import math
    sys.setrecursionlimit(100010)
    
    
    def main():
        items = sys.version.split()
        if items[0] == '3.10.6':
            fp = open("in.txt")
        else:
            fp = sys.stdin
        s = fp.readline().strip()
        n = len(s)
        rl, ll = [], []
        i = 0
        while i < n:
            bi = i
            while i < n and s[i] == 'R':
                i += 1
            rl.append(i - bi)
            bi = i
            while i < n and s[i] == 'L':
                i += 1
            ll.append(i - bi)
        m = len(rl)
        ans = []
        for i in range(m):
            s = ll[i] + rl[i]
            temp = [0] * s
            if s & 1 == 0:
                temp[rl[i]] = temp[rl[i] - 1] = s // 2
            else:
                if rl[i] > ll[i]:
                    temp[rl[i] - 1] = s // 2 + 1
                    temp[rl[i]] = s // 2
                else:
                    temp[rl[i] - 1] = s // 2
                    temp[rl[i]] = s // 2 + 1
                times = max(ll[i], rl[i]) - 1
                if times & 1:
                    temp[rl[i] - 1], temp[rl[i]] = temp[rl[i]], temp[rl[i] - 1]
            ans += temp
        print(*ans)
    
    
    if __name__ == "__main__":
        main()
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60

    E
    这种一个加一一个减一的操作,应该马上想到其和是不变的
    然后遍历可以被总和整除的自然数
    对于每个因数,先进行模运算,然后排序,将左边的减1,右边的加1,找到一个分界点。

    # -*- coding: utf-8 -*-
    # @time     : 2023/6/2 13:30
    # @author   : yhdu@tongwoo.cn
    # @desc     :
    # @file     : atcoder.py
    # @software : PyCharm
    import bisect
    import copy
    import sys
    from sortedcontainers import SortedList
    from collections import defaultdict, Counter, deque
    from functools import lru_cache, cmp_to_key
    import heapq
    import math
    sys.setrecursionlimit(100010)
    
    
    def check(arr, k, p):
        t = [x % p for x in arr]
        t.sort()
        n = len(arr)
        pre = 0
        st = sum(t)
        for i in range(n):
            pre += t[i]
            if pre > k:
                return False
            if pre == (n - 1 - i) * p - (st - pre):
                return True
        return False
    
    
    def main():
        items = sys.version.split()
        if items[0] == '3.10.6':
            fp = open("in.txt")
        else:
            fp = sys.stdin
        n, k = map(int, fp.readline().split())
        a = list(map(int, fp.readline().split()))
        sa = sum(a)
        p = 1
        ans = 0
        while p * p <= sa:
            if sa % p == 0:
                p0, p1 = p, sa // p
                if check(a, k, p0):
                    ans = p0
                if check(a, k, p1):
                    ans = p1
                    break
            p += 1
        print(ans)
    
    
    if __name__ == "__main__":
        main()
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
  • 相关阅读:
    81 · 寻找数据流的中位数
    【三维目标检测】VoteNet(二)
    五子棋小游戏——Java
    SQLAlchemy 在 Flask 应用中的使用和最佳实践
    【java吐血整理】
    Web前端:React有哪些特征?什么时候使用React?
    创建Anaconda虚拟Python环境的方法
    MongoDB相关基础操作(库、集合、文档)
    第十七届全国人机语音通讯学术会议(NCMMSC 2022) | 早鸟票开放注册了
    Spring Cloud Config 分布式配置中心
  • 原文地址:https://blog.csdn.net/acrux1985/article/details/134003099