• AtCoder abc 133


    C - Remainder Minimization 2019
    如果LR相差在2019内,那么遍历LR
    否则可以视作为1…2019的遍历

    D - Rain Flows into Dams
    设解为 M 1 , M 2 . . . M n M_1,M_2...M_n M1,M2...Mn
    ∵ M 1 + M 2 = 2 A 1 \because M_1+M_2=2A_1 M1+M2=2A1
    M 2 + M 3 = 2 A 2 M_2+M_3=2A_2 M2+M3=2A2
    . . . ... ...
    左边相加可以得到
    M 1 + . . . + M n = A 1 + . . . + A n M_1+...+M_n=A_1+...+A_n M1+...+Mn=A1+...+An
    M的和即可求出。
    剩下由于M长度为奇数,可以凑出 M 1 + M 2 + . . . + M n − 1 M_1+M_2+...+M_{n-1} M1+M2+...+Mn1
    即求得 M n M_n Mn
    接着从后往前计算M的各项。

    # -*- 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
        n = int(fp.readline())
        a = list(map(int, fp.readline().split()))
        sb = sum(a)
        eb = 0
        for i in range(0, n - 1, 2):
            eb += a[i] * 2
        b = [0] * n
        b[-1] = sb - eb
        for i in range(n - 2, -1, -1):
            b[i] = 2 * a[i] - b[i + 1]
        print(*b)
    
    
    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

    E - Virus Tree 2
    普通的乘法原理,画图想一想
    根节点可以乘K
    接下来的第一层子节点,第一个可以乘K-1,第二个乘K-2,依次递减
    第二层子节点,第一个点可以乘K-2,第二个乘K-3,依次递减
    之后的子节点和第二层相同

    # -*- 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
        mod = 10 ** 9 + 7
        n, m = map(int, fp.readline().split())
        g = [[] for _ in range(n + 1)]
        for i in range(n - 1):
            u, v = map(int, fp.readline().split())
            g[u].append(v)
            g[v].append(u)
        ans = 1
    
        def go(cur, fa):
            nonlocal ans
            if fa == -1:
                t = m - 1
            else:
                t = m - 2
            for child in g[cur]:
                if fa == child:
                    continue
                ans = ans * t % mod
                t -= 1
            for child in g[cur]:
                if fa == child:
                    continue
                go(child, cur)
    
        go(1, -1)
        ans = ans * m % mod
    
        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
  • 相关阅读:
    hadoop 安装到配置-2021-11-4
    PHP低版本安全问题
    文心一言 VS 讯飞星火 VS chatgpt (96)-- 算法导论9.3 1题
    倒计时列表实现(小程序端&Vue)
    Java各种数据结构的定义(如何写测试用例)
    【JVM基础篇】类加载器分类介绍
    黑暗爆炸 #1059. [ZJOI2007]矩阵游戏
    CSP直通车 | 在线直播认证培训双周末班 火热报名中
    CSP2023 游记
    虚拟机信息巡检脚本
  • 原文地址:https://blog.csdn.net/acrux1985/article/details/133947601