zoukankan      html  css  js  c++  java
  • 04.3 bisect可维护序列

    代码

    bisect 有用二分查找实现,故效率挺高,但是需要的是升序的有序序列

    # 可维护序列
    import bisect
    from collections import deque
    # deque 队列
    # 维护已排序的序列-升序
    # 二分查找
    
    # 创建一个队列
    inter_list = deque()
    # insort 插入数据
    bisect.insort(inter_list, 3)
    bisect.insort(inter_list, 2)
    bisect.insort(inter_list, 5)
    bisect.insort(inter_list, 1)
    bisect.insort(inter_list, 6)
    print(inter_list)   # [1, 2, 3, 5, 6]
    
    # bisect 查
    print(bisect.bisect(inter_list, 6))
    print(bisect.bisect_right(inter_list, 3))
    
    
  • 相关阅读:
    nyoj 16 矩形嵌套
    nyoj 44 子串和
    nyoj 448 寻找最大数
    nyoj 14 会场安排问题
    hdoj 1008 Elevator
    bzoj1588
    bzoj3224
    bzoj1503
    bzoj1834
    bzoj1066
  • 原文地址:https://www.cnblogs.com/zy7y/p/14193833.html
Copyright © 2011-2022 走看看