{"id":3261,"date":"2023-10-23T11:24:48","date_gmt":"2023-10-23T03:24:48","guid":{"rendered":"https:\/\/white-night.club\/?p=3261"},"modified":"2024-02-26T09:06:28","modified_gmt":"2024-02-26T01:06:28","slug":"ad89","status":"publish","type":"post","link":"https:\/\/white-night.club\/index.php\/2023\/10\/23\/ad89\/","title":{"rendered":"1893.\u00a0\u68c0\u67e5\u662f\u5426\u533a\u57df\u5185\u6240\u6709\u6574\u6570\u90fd\u88ab\u8986\u76d6"},"content":{"rendered":"\n<p>\u7ed9\u4f60\u4e00\u4e2a\u4e8c\u7ef4\u6574\u6570\u6570\u7ec4&nbsp;<code>ranges<\/code>&nbsp;\u548c\u4e24\u4e2a\u6574\u6570&nbsp;<code>left<\/code>&nbsp;\u548c&nbsp;<code>right<\/code>&nbsp;\u3002\u6bcf\u4e2a&nbsp;<code>ranges[i] = [start<sub>i<\/sub>, end<sub>i<\/sub>]<\/code>&nbsp;\u8868\u793a\u4e00\u4e2a\u4ece&nbsp;<code>start<sub>i<\/sub><\/code>&nbsp;\u5230&nbsp;<code>end<sub>i<\/sub><\/code>&nbsp;\u7684&nbsp;<strong>\u95ed\u533a\u95f4<\/strong>&nbsp;\u3002<\/p>\n\n\n\n<p>\u5982\u679c\u95ed\u533a\u95f4&nbsp;<code>[left, right]<\/code>&nbsp;\u5185\u6bcf\u4e2a\u6574\u6570\u90fd\u88ab&nbsp;<code>ranges<\/code>&nbsp;\u4e2d&nbsp;<strong>\u81f3\u5c11\u4e00\u4e2a<\/strong>&nbsp;\u533a\u95f4\u8986\u76d6\uff0c\u90a3\u4e48\u8bf7\u4f60\u8fd4\u56de&nbsp;<code>true<\/code>&nbsp;\uff0c\u5426\u5219\u8fd4\u56de&nbsp;<code>false<\/code>&nbsp;\u3002<\/p>\n\n\n\n<p>\u5df2\u77e5\u533a\u95f4&nbsp;<code>ranges[i] = [start<sub>i<\/sub>, end<sub>i<\/sub>]<\/code>&nbsp;\uff0c\u5982\u679c\u6574\u6570&nbsp;<code>x<\/code>&nbsp;\u6ee1\u8db3&nbsp;<code>start<sub>i<\/sub> &lt;= x &lt;= end<sub>i<\/sub><\/code>&nbsp;\uff0c\u90a3\u4e48\u6211\u4eec\u79f0\u6574\u6570<code>x<\/code>&nbsp;\u88ab\u8986\u76d6\u4e86\u3002<\/p>\n\n\n\n<p><strong>\u793a\u4f8b 1\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>\u8f93\u5165\uff1a<\/strong>ranges = [[1,2],[3,4],[5,6]], left = 2, right = 5\n<strong>\u8f93\u51fa\uff1a<\/strong>true\n<strong>\u89e3\u91ca\uff1a<\/strong>2 \u5230 5 \u7684\u6bcf\u4e2a\u6574\u6570\u90fd\u88ab\u8986\u76d6\u4e86\uff1a\n- 2 \u88ab\u7b2c\u4e00\u4e2a\u533a\u95f4\u8986\u76d6\u3002\n- 3 \u548c 4 \u88ab\u7b2c\u4e8c\u4e2a\u533a\u95f4\u8986\u76d6\u3002\n- 5 \u88ab\u7b2c\u4e09\u4e2a\u533a\u95f4\u8986\u76d6\u3002\n<\/pre>\n\n\n\n<p><strong>\u793a\u4f8b 2\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>\u8f93\u5165\uff1a<\/strong>ranges = [[1,10],[10,20]], left = 21, right = 21\n<strong>\u8f93\u51fa\uff1a<\/strong>false\n<strong>\u89e3\u91ca\uff1a<\/strong>21 \u6ca1\u6709\u88ab\u4efb\u4f55\u4e00\u4e2a\u533a\u95f4\u8986\u76d6\u3002\n<\/pre>\n\n\n\n<p><strong>\u63d0\u793a\uff1a<\/strong><\/p>\n\n\n\n<ul>\n<li><code>1 &lt;= ranges.length &lt;= 50<\/code><\/li>\n\n\n\n<li><code>1 &lt;= start<sub>i<\/sub> &lt;= end<sub>i<\/sub> &lt;= 50<\/code><\/li>\n\n\n\n<li><code>1 &lt;= left &lt;= right &lt;= 50<\/code><\/li>\n<\/ul>\n\n\n\n<div style=\"height:60px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<blockquote class=\"wp-block-quote has-luminous-vivid-amber-color has-text-color\">\n<p>\u89e3\u9898\u601d\u8def<\/p>\n<cite><em>\u5dee\u5206\u6570\u7ec4<\/em><\/cite><\/blockquote>\n\n\n\n<p>\u6628\u5929\u5199\u4e86\u9053\u5dee\u5206\u6570\u7ec4\u7684\u9898\uff0c\u4eca\u5929\u7ee7\u7eed\u5de9\u56fa\u4e00\u4e0b\u3002<\/p>\n\n\n\n<p>\u7ef4\u62a4\u5dee\u5206\u6570\u7ec4\u6ca1\u5565\u95ee\u9898\uff0c\u8fd8\u662fleft-right+1\u8fd9\u4e24\u4e2a\u533a\u95f4\u503c\u4f5c\u64cd\u4f5c\u3002<\/p>\n\n\n\n<p>\u201c\u5224\u65ad\u533a\u95f4\u6240\u6709\u503c\u662f\u5426\u88ab\u8986\u76d6\u201d\uff0c\u90a3\u4e48\u53cd\u8fc7\u6765\u60f3\u5c31\u662f\u627e\u6ca1\u88ab\u8986\u76d6\u7684\u503c\u3002\u6ca1\u88ab\u8986\u76d6\u7684\u503cx\u5728diff[x]\u4e2d\u7684\u524d\u7f00\u548c\u7b49\u4e8e0\uff0c\u6240\u4ee5\u76f4\u63a5\u4f5c\u5224\u65ad\u7136\u540ereturn false\u3002<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2b2b2b;color:#c7c7c7\">C++<\/span><span role=\"button\" tabindex=\"0\" data-code=\"class Solution {\npublic:\n    bool isCovered(vector&lt;vector&lt;int&gt;&gt;&amp; ranges, int left, int right) {\n        int diff[52]{0};\n        int size=ranges.size();\n        for(int i=0;i&lt;size;i++)\n        {\n            diff[ranges[i][0]]++;\n            diff[ranges[i][1]+1]--;\n        }\n        int sum=0;\n        for(int i=0;i&lt;52;i++)\n        {\n            sum+=diff[i];\n            if(i&gt;=left&amp;&amp;i&lt;=right&amp;&amp;sum&lt;=0)\n            {\n                return false;\n            }\n        }\n        return true;\n    }\n};\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #569CD6\">class<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #4EC9B0\">Solution<\/span><span style=\"color: #D4D4D4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">public:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #569CD6\">bool<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #DCDCAA\">isCovered<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #4EC9B0\">vector<\/span><span style=\"color: #D4D4D4\">&lt;<\/span><span style=\"color: #4EC9B0\">vector<\/span><span style=\"color: #D4D4D4\">&lt;<\/span><span style=\"color: #569CD6\">int<\/span><span style=\"color: #D4D4D4\">&gt;&gt;<\/span><span style=\"color: #569CD6\">&amp;<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">ranges<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #569CD6\">int<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">left<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #569CD6\">int<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">right<\/span><span style=\"color: #D4D4D4\">) {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">        <\/span><span style=\"color: #569CD6\">int<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">diff<\/span><span style=\"color: #D4D4D4\">[<\/span><span style=\"color: #B5CEA8\">52<\/span><span style=\"color: #D4D4D4\">]{<\/span><span style=\"color: #B5CEA8\">0<\/span><span style=\"color: #D4D4D4\">};<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">        <\/span><span style=\"color: #569CD6\">int<\/span><span style=\"color: #D4D4D4\"> size=<\/span><span style=\"color: #9CDCFE\">ranges<\/span><span style=\"color: #D4D4D4\">.<\/span><span style=\"color: #DCDCAA\">size<\/span><span style=\"color: #D4D4D4\">();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">        <\/span><span style=\"color: #C586C0\">for<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #569CD6\">int<\/span><span style=\"color: #D4D4D4\"> i=<\/span><span style=\"color: #B5CEA8\">0<\/span><span style=\"color: #D4D4D4\">;i&lt;size;i++)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">        {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">            <\/span><span style=\"color: #9CDCFE\">diff<\/span><span style=\"color: #D4D4D4\">[<\/span><span style=\"color: #9CDCFE\">ranges<\/span><span style=\"color: #D4D4D4\">[i][<\/span><span style=\"color: #B5CEA8\">0<\/span><span style=\"color: #D4D4D4\">]]++;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">            <\/span><span style=\"color: #9CDCFE\">diff<\/span><span style=\"color: #D4D4D4\">[<\/span><span style=\"color: #9CDCFE\">ranges<\/span><span style=\"color: #D4D4D4\">[i][<\/span><span style=\"color: #B5CEA8\">1<\/span><span style=\"color: #D4D4D4\">]+<\/span><span style=\"color: #B5CEA8\">1<\/span><span style=\"color: #D4D4D4\">]--;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">        }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">        <\/span><span style=\"color: #569CD6\">int<\/span><span style=\"color: #D4D4D4\"> sum=<\/span><span style=\"color: #B5CEA8\">0<\/span><span style=\"color: #D4D4D4\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">        <\/span><span style=\"color: #C586C0\">for<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #569CD6\">int<\/span><span style=\"color: #D4D4D4\"> i=<\/span><span style=\"color: #B5CEA8\">0<\/span><span style=\"color: #D4D4D4\">;i&lt;<\/span><span style=\"color: #B5CEA8\">52<\/span><span style=\"color: #D4D4D4\">;i++)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">        {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">            sum+=<\/span><span style=\"color: #9CDCFE\">diff<\/span><span style=\"color: #D4D4D4\">[i];<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">            <\/span><span style=\"color: #C586C0\">if<\/span><span style=\"color: #D4D4D4\">(i&gt;=left&amp;&amp;i&lt;=right&amp;&amp;sum&lt;=<\/span><span style=\"color: #B5CEA8\">0<\/span><span style=\"color: #D4D4D4\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">            {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">                <\/span><span style=\"color: #C586C0\">return<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #569CD6\">false<\/span><span style=\"color: #D4D4D4\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">            }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">        }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">        <\/span><span style=\"color: #C586C0\">return<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #569CD6\">true<\/span><span style=\"color: #D4D4D4\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">};<\/span><\/span><\/code><\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Leetcode\u9898\u76ee\uff1a\u5dee\u5206\u6570\u7ec4<\/p>\n","protected":false},"author":1,"featured_media":2827,"comment_status":"open","ping_status":"","sticky":false,"template":"base","format":"standard","meta":{"footnotes":""},"categories":[42,25],"tags":[38],"_links":{"self":[{"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/posts\/3261"}],"collection":[{"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/comments?post=3261"}],"version-history":[{"count":0,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/posts\/3261\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/media\/2827"}],"wp:attachment":[{"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/media?parent=3261"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/categories?post=3261"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/tags?post=3261"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}