• AtCoder abc137


    C Green Bin
    map计数
    D Summer Vacation
    贪心,但没贪成功
    应该从后往前考虑,按天计算,维护一个当前可以取到的最大堆

    # -*- 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, k = map(int, fp.readline().split())
        items = []
        for i in range(n):
            a, b = map(int, fp.readline().split())
            items.append([a, b])
        # 从截止日期小到大排序
        # 例如当前的截止日期是1天,那么把1天内可以运行完的都放入堆中
        items.sort(key=lambda x: x[0])
        qu = []
        i = 0
        vis = [0] * n
        ans = 0
        for day in range(1, k + 1):
            while i < n and items[i][0] <= day:
                heapq.heappush(qu, (-items[i][1], i))
                i += 1
            # lazy更新,每一个item进出队列一次
            while len(qu) > 0:
                top = heapq.heappop(qu)
                v, idx = top
                if vis[idx] == 0:
                    v = -v
                    ans += v
                    vis[idx] = 1
                    break
        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

    E Coins Respawn
    很不错的图论
    首先易见每条边都减一次cost。
    由于有环,只需要用bellman-ford计算最短路
    问题是如何判断松弛点对于最后的结果有影响。答案是该松弛点应该在从1到N的路径上。
    因此用两个dfs判断每个点是否会被1访问,被N反向访问。

    # -*- 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, m, p = map(int, fp.readline().split())
        g = []
        wg = [[] for _ in range(n)]
        rg = [[] for _ in range(n)]
        dist = [-10 ** 10] * n
        dist[0] = 0
        reach_n = [0] * n
        reach_1 = [0] * n
    
        def dfs(node):
            reach_n[node] = 1
            for nxt in rg[node]:
                if reach_n[nxt] == 0:
                    dfs(nxt)
    
        def dfs1(node):
            reach_1[node] = 1
            for nxt in wg[node]:
                if reach_1[nxt] == 0:
                    dfs1(nxt)
    
        for i in range(m):
            u, v, w = map(int, fp.readline().split())
            u, v, w = u - 1, v - 1, w - p
            g.append([u, v, w])
            rg[v].append(u)
            wg[u].append(v)
    
        dfs1(0)
        dfs(n - 1)
    
        for _ in range(n - 1):
            for i in range(m):
                u, v, w = g[i]
                if dist[v] < dist[u] + w:
                    dist[v] = dist[u] + w
        change = 0
        for i in range(m):
            u, v, w = g[i]
            if dist[v] < dist[u] + w and reach_n[v] and reach_1[v]:
                change = 1
        if change:
            print(-1)
        else:
            if dist[n - 1] < 0:
                print(0)
            else:
                print(dist[n - 1])
    
    
    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
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76

    F - Polynomial Construction
    费尔马小定理的灵活应用。但是我不会。
    已知 a p − 1 ≡ 1 ( m o d   p ) a^{p-1}\equiv1 (mod \space p) ap11(mod p)
    则对于任意 x , p x,p x,p
    1 − ( x − d ) p − 1 ≡ 1   x = d 1-(x-d)^{p-1} \equiv 1 \space x=d 1(xd)p11 x=d
    1 − ( x − d ) p − 1 ≡ 0   x ≠ d 1-(x-d)^{p-1} \equiv 0 \space x \neq d 1(xd)p10 x=d
    记上述式子为 f ( x , d ) f(x,d) f(x,d)
    该式的意义在于,假如我们构造一个多项式
    F ( x ) = ∑ d = 1 p − 1 f ( x , d ) F(x)=\sum_{d=1}^{p-1}f(x,d) F(x)=d=1p1f(x,d)只有当x取到d时,多项式 f ( x , d ) f(x,d) f(x,d)才模1,其余情况下多项式 f ( x , d ) f(x,d) f(x,d)均为0,也就是整个 F ( x ) F(x) F(x)和为1。
    所以我们遍历 a [ i ] a[i] a[i],当 a [ i ] = 1 a[i]=1 a[i]=1时,将 f ( x , d ) f(x,d) f(x,d)加入到多项式中。

    # -*- 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
        p = int(fp.readline())
        a = list(map(int, fp.readline().split()))
        b = [0] * p
        cmb = [[0] * (p + 1) for _ in range(p + 1)]
        for j in range(p + 1):
            cmb[0][j] = 1
        for i in range(p + 1):
            cmb[i][0] = 1
            for j in range(1, p + 1):
                cmb[i][j] = (cmb[i - 1][j - 1] + cmb[i - 1][j]) % p
        for i in range(p):
            if a[i] == 1:
                np = 1
                for j in range(p):
                    t = -cmb[p - 1][j] * np
                    b[p - 1 - j] = (b[p - 1 - j] + t) % p
                    np = (np * -i) % p
                b[0] = (b[0] + 1) % p
        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
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
  • 相关阅读:
    【技术积累】HTML+CSS+JavaScript中的基础知识【二】
    4.验证面试高频问题整理(附答案)
    Android中EditText的密码显示与隐藏
    QT集成Protobuf
    C++ Primer学习笔记-----第十七章:标准款特殊设施
    【Flink读写外部系统】Flink异步访问外部系统_mysql
    LM2903VQPWRQ1比较器 LM73C0QDDCRQ1传感器的中文资料
    经纬高坐标转东北天坐标
    C语言每日一题—魔幻矩阵
    168.Hadoop(四):MapReduce基本概念,wordCount案例跑通,bean对象序列化
  • 原文地址:https://blog.csdn.net/acrux1985/article/details/134019101