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()

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()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值