{"blog_url":"https://inaz2.hatenablog.com/","published":"2013-04-11 03:22:56","version":"1.0","title":" Python\u3067\u30d2\u30fc\u30d7\u69cb\u9020\u3092\u4f7f\u3046\uff08heapq\u30e2\u30b8\u30e5\u30fc\u30eb\uff09","width":"100%","author_url":"https://blog.hatena.ne.jp/inaz2/","author_name":"inaz2","height":"190","image_url":null,"type":"rich","url":"https://inaz2.hatenablog.com/entry/2013/04/11/032256","description":"\u5e38\u306b\u6700\u521d\u306e\u8981\u7d20\u304c\u6700\u5c0f\u5024\uff08\u3042\u308b\u3044\u306f\u6700\u5927\u5024\uff09\u3068\u306a\u308b\u3088\u3046\u306a\u30ea\u30b9\u30c8\u304c\u5fc5\u8981\u306a\u5834\u5408\u3001\u30d2\u30fc\u30d7\u69cb\u9020\u3092\u7528\u3044\u308b\u3053\u3068\u3067\u6700\u5c0f\u5024\uff08\u6700\u5927\u5024\uff09\u306e\u53d6\u308a\u51fa\u3057\u3092O(1)\u3001\u8981\u7d20\u306e\u8ffd\u52a0\u3092O(log n)\u306e\u6642\u9593\u8a08\u7b97\u91cf\u3067\u884c\u3046\u3053\u3068\u304c\u3067\u304d\u308b\u3002 Python\u3067\u30d2\u30fc\u30d7\u3092\u6271\u3046\u5834\u5408\u3001heapq\u30e2\u30b8\u30e5\u30fc\u30eb\u304c\u4f7f\u3048\u308b\u3002 import heapq a = [6, 3, 2, 4, 5] heapq.heapify(a) # \u7834\u58ca\u7684 print a[0] # => 2 heapq.heappop(a) # \u6700\u5c0f\u5024\u3092\u30d2\u30fc\u30d7\u304b\u3089\u53d6\u308a\u51fa\u3059 print a[0] # => 3 heapq.heappush(a, 1) # \u30d2\u30fc\u30d7\u306b\u8981\u7d20\u3092\u8ffd\u52a0\u3059\u308b print a[0]\u2026","blog_title":"\u3082\u3082\u3044\u308d\u30c6\u30af\u30ce\u30ed\u30b8\u30fc","html":"<iframe src=\"https://hatenablog-parts.com/embed?url=https%3A%2F%2Finaz2.hatenablog.com%2Fentry%2F2013%2F04%2F11%2F032256\" title=\" Python\u3067\u30d2\u30fc\u30d7\u69cb\u9020\u3092\u4f7f\u3046\uff08heapq\u30e2\u30b8\u30e5\u30fc\u30eb\uff09 - \u3082\u3082\u3044\u308d\u30c6\u30af\u30ce\u30ed\u30b8\u30fc\" class=\"embed-card embed-blogcard\" scrolling=\"no\" frameborder=\"0\" style=\"display: block; width: 100%; height: 190px; max-width: 500px; margin: 10px 0px;\"></iframe>","categories":["Python"],"provider_name":"Hatena Blog","provider_url":"https://hatena.blog"}