{"id":171,"date":"2018-10-20T01:30:45","date_gmt":"2018-10-19T17:30:45","guid":{"rendered":"http:\/\/SmokeyDays.top\/wordpress\/?p=171"},"modified":"2018-10-20T01:34:20","modified_gmt":"2018-10-19T17:34:20","slug":"lp1792-%e5%9b%bd%e5%ae%b6%e9%9b%86%e8%ae%ad%e9%98%9f-%e7%a7%8d%e6%a0%91","status":"publish","type":"post","link":"http:\/\/SmokeyDays.top\/wordpress\/2018\/10\/20\/lp1792-%e5%9b%bd%e5%ae%b6%e9%9b%86%e8%ae%ad%e9%98%9f-%e7%a7%8d%e6%a0%91\/","title":{"rendered":"lp1792 \u56fd\u5bb6\u96c6\u8bad\u961f \u79cd\u6811"},"content":{"rendered":"<p>\u9996\u5148\u62ff\u5230\u9898\u9762\u5f88\u5bb9\u6613\u53ef\u4ee5\u60f3\u5230\u7684\u662f\u72b6\u538bDP\uff0c\u72b6\u6001\u8f6c\u79fb\u65b9\u7a0b\u5f88\u5bb9\u6613\u53ef\u4ee5\u63a8\u51fa\u6765\u3002<br \/>\n\u4f46\u662f\u8fd9\u4e48\u505a\u7684\u590d\u6742\u5ea6\u662f\\(O(n^2)\\)\u7684\uff0c\u53ea\u80fd\u62ff\u523050\u5206\u3002<br \/>\n\u6211\u4eec\u6df1\u5165\u5730\u8003\u8651\u8fd9\u4e00\u9898\u7684\u6027\u8d28\uff0c\u6211\u4eec\u53d1\u73b0\uff0c\u5bf9\u4e8e\u8fd9\u4e2a\u73af\uff0c\u5982\u679c\u53d6\u7528\u4e86\u4e0a\u9762\u7684\u67d0\u4e00\u4e2a\u70b9\uff0c\u90a3\u4e48\u8fd9\u4e2a\u70b9\u7684\u4e24\u4e2a\u90bb\u70b9\u90fd\u4e0d\u53ef\u53d6\u3002<br \/>\n\u8d2a\u5fc3\u5730\u4f9d\u636e\u6743\u503c\u4ece\u5927\u5230\u5c0f\u8003\u8651\uff0c\u5982\u679c\u4e00\u4e2a\u70b9\u7684\u4e24\u4e2a\u90bb\u70b9\u52a0\u8d77\u6765\u90fd\u4e0d\u5982\u5b83\u5927\u7684\u8bdd\uff0c\u90a3\u4e48\u53d6\u90bb\u70b9\u4e2d\u7684\u4efb\u610f\u4e00\u4e2a\u90fd\u4e0d\u5982\u53d6\u8fd9\u4e2a\u70b9\u3002<br \/>\n\u5982\u679c\u8fd9\u4e2a\u70b9\u7684\u4e24\u4e2a\u90bb\u70b9\u52a0\u4e00\u8d77\u6bd4\u5b83\u5927\uff0c\u90a3\u5c31\u8003\u8651\u4e24\u79cd\u60c5\u51b5\uff0c\u4e00\u79cd\u60c5\u51b5\u662f\u9009\u62e9\u8fd9\u4e2a\u70b9\uff0c\u4e00\u79cd\u60c5\u51b5\u662f\u9009\u62e9\u8fd9\u4e2a\u70b9\u7684\u4e24\u4e2a\u90bb\u70b9\u3002<br \/>\n\uff08\u5f88\u5bb9\u6613\u53ef\u4ee5\u77e5\u9053\uff0c\u5982\u679c\u4e24\u4e2a\u90bb\u70b9\u53ea\u9009\u4e00\u4e2a\uff0c\u90a3\u662f\u4e00\u5b9a\u6ca1\u6709\u9009\u8fd9\u4e2a\u70b9\u4f18\u7684\u3002\uff09<br \/>\n\u6211\u4eec\u8003\u8651\u5148\u53d6\u4e86\u8fd9\u4e2a\u70b9\uff0c\u518d\u8f6c\u53d8\u4e3a\u53d6\u8fd9\u4e2a\u70b9\u7684\u4e24\u4e2a\u90bb\u70b9\u7684\u60c5\u51b5\u3002\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u603b\u6743\u503c\u5c31\u4f1a\u51cf\u53bb\u8fd9\u4e2a\u70b9\u7684\u6743\u503c\uff0c\u5e76\u4e14\u52a0\u4e0a\u8fd9\u4e2a\u70b9\u7684\u4e24\u4e2a\u90bb\u70b9\u7684\u6743\u503c\u3002<br \/>\n\u6211\u4eec\u8003\u8651\u4e00\u4e2a\u6709\u8da3\u7684\u6027\u8d28\u3002\u5982\u679c\u4e00\u4e2a\u70b9\u7684\u4e24\u4e2a\u90bb\u70b9\u90fd\u9009\u53d6\u4e86\uff0c\u90a3\u4e48\u5f71\u54cd\u5230\u7684\u201c\u4e0d\u53ef\u88ab\u9009\u53d6\u533a\u57df\u201d\u7684\u5927\u5c0f\uff0c\u662f\u548c\u4e09\u4e2a\u90fd\u9009\u662f\u76f8\u540c\u7684\u3002<br \/>\n\u56e0\u6b64\uff0c\u6211\u4eec\u8003\u8651\u7a76\u7adf\u5e94\u8be5\u9009\u53d6\u8fd9\u4e2a\u70b9\u8fd8\u662f\u8fd9\u4e2a\u70b9\u7684\u4e24\u4e2a\u90bb\u70b9\u3002\u6211\u4eec\u8003\u8651\u6bcf\u5f53\u6316\u53bb\u4e00\u4e2a\u70b9\u7684\u65f6\u5019\uff0c\u90fd\u628a\u5b83\u7684\u4e24\u4e2a\u90bb\u70b9\u6807\u8bb0\u4e3a\u6d88\u5931\u3002<br \/>\n\u8fd9\u65f6\u5019\u5bf9\u4e0d\u53ef\u9009\u53d6\u533a\u57df\u7684\u5f71\u54cd\u5df2\u7ecf\u786e\u5b9a\u4e86\uff0c\u56e0\u6b64\u53ea\u8981\u786e\u5b9a\u5bf9\u5bf9\u6743\u503c\u7684\u5f71\u54cd\u3002<br \/>\n\u90a3\u4e48\u6211\u4eec\u8003\u8651\u5efa\u4e00\u4e2a\u865a\u70b9\uff0c\u66ff\u4ee3\u5728\u8d2a\u5fc3\u9009\u53d6\u7684\u90a3\u4e2a\u70b9\u4ee5\u53ca\u4e24\u4e2a\u76f8\u90bb\u7684\u4f4d\u7f6e\u3002\u8fd9\u4e2a\u865a\u70b9\u7684\u6743\u503c\u76f8\u5f53\u4e8e\u90bb\u70b9\u7684\u6743\u503c\u548c\u51cf\u53bb\u539f\u70b9\u7684\u6743\u503c\u3002<br \/>\n\u5bf9\u4e8e\u8fd9\u4e2a\u865a\u70b9\uff0c\u6211\u4eec\u628a\u5b83\u5f53\u505a\u8fd9\u4e2a\u73af\u4e0a\u672c\u6765\u5c31\u5b58\u5728\u7684\u4e00\u4e2a\u70b9\u6765\u5904\u7406\u5373\u53ef\u3002<br \/>\n\u6240\u4ee5\u53ef\u4ee5\u8003\u8651\u7528\u5806+\u53cc\u5411\u94fe\u8868\u6765\u7ef4\u62a4\u3002<\/p>\n<p>\u987a\u4fbf\u63d0\u4e00\u53e5\uff0c\u8fd9\u662f\u4e00\u9053\u4e09\u500d\u7ecf\u9a8c\u9898\uff0c\u5b83\u7684\u4eb2\u4eba\u4eec\uff1a<br \/>\nlp3620 APIO\/CTSC2007 \u6570\u636e\u5907\u4efd\uff0clp1484 \u79cd\u6811<br \/>\n\u524d\u8005\u53ea\u8981\u5dee\u5206\u4e00\u4e0b\uff0c\u8fb9\u8f6c\u70b9\uff0c\u6539\u5927\u5c0f\u5224\u65ad\u4ee5\u540e\u7684\u8fb9\u754c\uff0c\u518d\u6539\u4e00\u4e0b\u5355\u8c03\u961f\u5217\uff1b\u540e\u8005\u53ea\u8981\u5224\u4e00\u4e0b\u8d1f\u6570\u60c5\u51b5\u3002<\/p>\n<pre class=\"pure-highlightjs\"><code class=\"cpp\">#include&lt;iostream&gt;\r\n#include&lt;cstdio&gt;\r\n#include&lt;queue&gt;\r\nusing namespace std;\r\n\r\nint n,m,a[200005],l[200005],r[200005],nw,nw2;\r\nbool ext[200005];\r\ntypedef pair&lt;int,int&gt; pii;\r\npriority_queue&lt;pii&gt; q;\r\nvoid init(){\r\n\tscanf(\"%d%d\",&amp;n,&amp;m);\r\n\tfor(int i=1;i&lt;=n;++i){\r\n\t\tscanf(\"%d\",&amp;a[i]);\r\n\t\tq.push((pii){a[i],i});\r\n\t\text[i]=0;\r\n\t}\r\n\tif(m&gt;(n&gt;&gt;1)){\r\n\t\tputs(\"Error!\");\r\n\t\treturn;\r\n\t}\r\n\tfor(int i=2;i&lt;=n;++i){\r\n\t\tl[i]=i-1;\r\n\t}\r\n\tl[1]=n;\r\n\tfor(int i=1;i&lt;n;++i){\r\n\t\tr[i]=i+1;\r\n\t}\r\n\tr[n]=1;\r\n\tlong long ans=0;\r\n\tfor(int i=1;i&lt;=m;++i){\r\n\t\twhile(!q.empty()&amp;&amp;ext[q.top().second]){\r\n\t\t\tq.pop();\r\n\t\t}\r\n\t\tnw=q.top().second;\r\n\t\tans+=q.top().first;\r\n\t\text[l[nw]]=1,ext[r[nw]]=1;\r\n\t\tnw2=a[l[nw]]+a[r[nw]]-q.top().first;\r\n\t\ta[nw]=nw2;\r\n\t\tl[nw]=l[l[nw]],r[nw]=r[r[nw]];\r\n\t\tr[l[nw]]=nw,l[r[nw]]=nw;\r\n\t\tq.pop();\r\n\t\tq.push((pii){nw2,nw});\r\n\t}\r\n\tprintf(\"%lld\",ans);\r\n}\r\n\r\nint main(){\r\n\tinit();\r\n\treturn 0;\r\n}<\/code><\/pre>\n<p>\u987a\u4fbf\u8d34\u4e00\u4e0b\u540e\u9762\u4e24\u9898\u7684\u4ee3\u7801\uff1a<\/p>\n<pre class=\"pure-highlightjs\"><code class=\"cpp\">#include&lt;iostream&gt;\r\n#include&lt;cstdio&gt;\r\n#include&lt;queue&gt;\r\nusing namespace std;\r\nint n,m,a[500005],l[500005],r[500005],nw,nw2;\r\nbool ext[500005];\r\n\/\/lp1484 \u79cd\u6811 \r\ntypedef pair&lt;int,int&gt; pii;\r\npriority_queue&lt;pii&gt; q;\r\nvoid init(){\r\n\tscanf(\"%d%d\",&amp;n,&amp;m);\r\n\tfor(int i=1;i&lt;=n;++i){\r\n\t\tscanf(\"%d\",&amp;a[i]);\r\n\t\tq.push((pii){a[i],i});\r\n\t\text[i]=0;\r\n\t}\r\n\tif(m&gt;(n&gt;&gt;1)){\r\n\t\tputs(\"Error!\");\r\n\t\treturn;\r\n\t}\r\n\tfor(int i=1;i&lt;=n;++i){\r\n\t\tl[i]=i-1;\r\n\t}\r\n\tfor(int i=1;i&lt;=n;++i){\r\n\t\tr[i]=i+1;\r\n\t}\r\n\tlong long ans=0;\r\n\tfor(int i=1;i&lt;=m;++i){\r\n\t\twhile(!q.empty()&amp;&amp;ext[q.top().second]){\r\n\t\t\tq.pop();\r\n\t\t}\r\n\t\tif(q.top().first&lt;0){\r\n\t\t\tbreak;\r\n\t\t} \r\n\t\tnw=q.top().second;\r\n\t\tans+=q.top().first;\r\n\t\text[l[nw]]=1,ext[r[nw]]=1;\r\n\t\tnw2=a[l[nw]]+a[r[nw]]-q.top().first;\r\n\t\ta[nw]=nw2;\r\n\t\tl[nw]=l[l[nw]],r[nw]=r[r[nw]];\r\n\t\tr[l[nw]]=nw,l[r[nw]]=nw;\r\n\t\tq.pop();\r\n\t\tq.push((pii){nw2,nw});\r\n\t}\r\n\tprintf(\"%lld\",ans);\r\n}\r\n\r\nint main(){\r\n\tinit();\r\n\treturn 0;\r\n}<\/code><\/pre>\n<pre class=\"pure-highlightjs\"><code class=\"cpp\">#include&lt;iostream&gt;\r\n#include&lt;cstdio&gt;\r\n#include&lt;queue&gt;\r\n#include&lt;vector&gt;\r\nusing namespace std;\r\nint n,m,a[100005],l[100005],r[100005],nw,nw2;\r\nbool ext[100005];\r\n\/\/lp3620 APIOCTSC2007 \u6570\u636e\u5907\u4efd \r\ntypedef pair&lt;int,int&gt; pii;\r\npriority_queue&lt; pii,vector&lt;pii&gt;,greater&lt;pii&gt; &gt; q;\r\nvoid init(){\r\n\tscanf(\"%d%d\",&amp;n,&amp;m);\r\n\tfor(int i=1;i&lt;=n;++i){\r\n\t\tscanf(\"%d\",&amp;a[i]);\r\n\t\text[i]=0;\r\n\t}\r\n\tfor(int i=n;i&gt;=1;--i){\r\n\t\ta[i]-=a[i-1];\r\n\t}\r\n\tfor(int i=1;i&lt;n;++i){\r\n\t\ta[i]=a[i+1];\r\n\t\tq.push((pii){a[i],i});\r\n\t} \r\n\ta[0]=a[n]=0x3f3f3f3f; \r\n\tif(m&gt;(n&gt;&gt;1)){\r\n\t\tputs(\"Error!\");\r\n\t\treturn;\r\n\t}\r\n\tfor(int i=1;i&lt;n;++i){\r\n\t\tl[i]=i-1;\r\n\t}\r\n\tfor(int i=1;i&lt;n;++i){\r\n\t\tr[i]=i+1;\r\n\t}\r\n\tlong long ans=0;\r\n\tfor(int i=1;i&lt;=m;++i){\r\n\t\twhile(!q.empty()&amp;&amp;ext[q.top().second]){\r\n\t\t\tq.pop();\r\n\t\t}\r\n\t\tnw=q.top().second;\r\n\t\tans+=q.top().first;\r\n\t\text[l[nw]]=1,ext[r[nw]]=1;\r\n\t\tnw2=a[l[nw]]+a[r[nw]]-q.top().first;\r\n\t\ta[nw]=nw2;\r\n\t\tl[nw]=l[l[nw]],r[nw]=r[r[nw]];\r\n\t\tr[l[nw]]=nw,l[r[nw]]=nw;\r\n\t\tq.pop();\r\n\t\tq.push((pii){nw2,nw});\r\n\t}\r\n\tprintf(\"%lld\",ans);\r\n}\r\n\r\nint main(){\r\n\tinit();\r\n\treturn 0;\r\n}<\/code><\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u9996\u5148\u62ff\u5230\u9898\u9762\u5f88\u5bb9\u6613\u53ef\u4ee5\u60f3\u5230\u7684\u662f\u72b6\u538bDP\uff0c\u72b6\u6001\u8f6c\u79fb\u65b9\u7a0b\u5f88\u5bb9\u6613\u53ef\u4ee5\u63a8\u51fa\u6765\u3002 \u4f46\u662f\u8fd9\u4e48\u505a\u7684\u590d\u6742\u5ea6\u662f\\(O(n^2)\\ &hellip; <\/p>\n<p class=\"link-more\"><a href=\"http:\/\/SmokeyDays.top\/wordpress\/2018\/10\/20\/lp1792-%e5%9b%bd%e5%ae%b6%e9%9b%86%e8%ae%ad%e9%98%9f-%e7%a7%8d%e6%a0%91\/\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">\u201clp1792 \u56fd\u5bb6\u96c6\u8bad\u961f \u79cd\u6811\u201d<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[18,19,17,8,5],"tags":[],"_links":{"self":[{"href":"http:\/\/SmokeyDays.top\/wordpress\/wp-json\/wp\/v2\/posts\/171"}],"collection":[{"href":"http:\/\/SmokeyDays.top\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/SmokeyDays.top\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/SmokeyDays.top\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/SmokeyDays.top\/wordpress\/wp-json\/wp\/v2\/comments?post=171"}],"version-history":[{"count":1,"href":"http:\/\/SmokeyDays.top\/wordpress\/wp-json\/wp\/v2\/posts\/171\/revisions"}],"predecessor-version":[{"id":173,"href":"http:\/\/SmokeyDays.top\/wordpress\/wp-json\/wp\/v2\/posts\/171\/revisions\/173"}],"wp:attachment":[{"href":"http:\/\/SmokeyDays.top\/wordpress\/wp-json\/wp\/v2\/media?parent=171"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/SmokeyDays.top\/wordpress\/wp-json\/wp\/v2\/categories?post=171"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/SmokeyDays.top\/wordpress\/wp-json\/wp\/v2\/tags?post=171"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}