{"id":6012,"date":"2019-12-29T02:03:36","date_gmt":"2019-12-29T10:03:36","guid":{"rendered":"https:\/\/zxi.mytechroad.com\/blog\/?p=6012"},"modified":"2019-12-29T10:39:21","modified_gmt":"2019-12-29T18:39:21","slug":"binary-search-template","status":"publish","type":"post","link":"https:\/\/zxi.mytechroad.com\/blog\/template\/binary-search-template\/","title":{"rendered":"Binary search template \u4e8c\u5206\u641c\u7d22\u6a21\u677f"},"content":{"rendered":"\n<div class=\"responsive-tabs\">\n<h2 class=\"tabtitle\">Python<\/h2>\n<div class=\"tabcontent\">\n\n<pre lang=\"Python\">\n# Author: Huahua\n# Returns the smallest m in [l, r),\n# s.t. cond(m) == True\n# If not found returns r.\ndef binarySearch(l, r)\n  while l < r:\n    m = l + (r - l) \/\/ 2\n    if cond(m):\n      r = m\n    else\n      l = m + 1\n  return l\n<\/pre>\n<\/div><\/div>\n\n\n\n<div class=\"responsive-tabs\">\n<h2 class=\"tabtitle\">C++<\/h2>\n<div class=\"tabcontent\">\n\n<pre lang=\"c++\">\n\/\/ Author: Huahua\n\/\/ Returns the smallest m in [l, r),\n\/\/ s.t. cond(m) == True\n\/\/ If not found returns r.\nint binarySearch(int l, int r) {\n  while (l < r) {\n    int m = l + (r - l) \/ 2;\n    if (cond(m)) r = m;\n    else l = m + 1;\n  }\n  return l;\n}\n<\/pre>\n<\/div><\/div>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Related Articles<\/strong><\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/zxi.mytechroad.com\/blog\/sp\/sp5-binary-search\/\">https:\/\/zxi.mytechroad.com\/blog\/sp\/sp5-binary-search\/<\/a><\/li><li><a href=\"https:\/\/zxi.mytechroad.com\/blog\/sp\/binary-search-ii-sp17\/\">https:\/\/zxi.mytechroad.com\/blog\/sp\/binary-search-ii-sp17\/<\/a><\/li><\/ul>\n","protected":false},"excerpt":{"rendered":"<p># Author: Huahua # Returns the smallest m in [l, r), # s.t. cond(m) == True # If not found returns r. def binarySearch(l, r)&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[522],"tags":[52,459,428],"class_list":["post-6012","post","type-post","status-publish","format-standard","hentry","category-template","tag-binary-search","tag-ologn","tag-template","entry","simple"],"_links":{"self":[{"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/posts\/6012","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/comments?post=6012"}],"version-history":[{"count":5,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/posts\/6012\/revisions"}],"predecessor-version":[{"id":6017,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/posts\/6012\/revisions\/6017"}],"wp:attachment":[{"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/media?parent=6012"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/categories?post=6012"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/tags?post=6012"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}