{"id":622,"date":"2017-05-24T14:33:18","date_gmt":"2017-05-24T06:33:18","guid":{"rendered":"http:\/\/kylelv.com\/?p=622"},"modified":"2020-03-04T14:34:36","modified_gmt":"2020-03-04T06:34:36","slug":"bzoj-3389-usaco2004-deccleaning-shifts%e5%ae%89%e6%8e%92%e5%80%bc%e7%8f%ad-%e8%b4%aa%e5%bf%83","status":"publish","type":"post","link":"https:\/\/blog.kylelv.com\/?p=622","title":{"rendered":"bzoj 3389: [Usaco2004 Dec]Cleaning Shifts\u5b89\u6392\u503c\u73ed &#8212; \u8d2a\u5fc3"},"content":{"rendered":"\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_73 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-69fdef7489bf1\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-69fdef7489bf1\"  aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/blog.kylelv.com\/?p=622\/#3389_Usaco2004_DecCleaning_Shifts%E5%AE%89%E6%8E%92%E5%80%BC%E7%8F%AD\" title=\"3389: [Usaco2004 Dec]Cleaning Shifts\u5b89\u6392\u503c\u73ed\">3389: [Usaco2004 Dec]Cleaning Shifts\u5b89\u6392\u503c\u73ed<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/blog.kylelv.com\/?p=622\/#Description\" title=\"Description\">Description<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/blog.kylelv.com\/?p=622\/#Input\" title=\"Input\">Input<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/blog.kylelv.com\/?p=622\/#Output\" title=\"Output\">Output<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/blog.kylelv.com\/?p=622\/#Sample_Input\" title=\"Sample Input\">Sample Input<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/blog.kylelv.com\/?p=622\/#Sample_Output\" title=\"Sample Output\">Sample Output<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/blog.kylelv.com\/?p=622\/#HINT\" title=\"HINT\">HINT<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"3389_Usaco2004_DecCleaning_Shifts%E5%AE%89%E6%8E%92%E5%80%BC%E7%8F%AD\"><\/span>3389: [Usaco2004 Dec]Cleaning Shifts\u5b89\u6392\u503c\u73ed<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Time Limit:&nbsp;1 Sec&nbsp;&nbsp;Memory Limit:&nbsp;128 MB<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Description\"><\/span>Description<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;\u4e00\u5929\u6709T(1\u2264T\u226410^6)\u4e2a\u65f6\u6bb5\uff0e\u7ea6\u7ff0\u6b63\u6253\u7b97\u5b89\u6392\u4ed6\u7684N(1\u2264N\u226425000)\u53ea\u5976\u725b\u6765\u503c\u73ed\uff0c\u6253\u626b\u6253\u626b\u725b\u68da\u536b\u751f\uff0e\u6bcf\u53ea\u5976\u725b\u90fd\u6709\u81ea\u5df1\u7684\u7a7a\u95f2\u65f6\u95f4\u6bb5[Si\uff0cEi](1\u2264Si\u2264Ei\u2264T)\uff0c\u53ea\u80fd\u628a\u7a7a\u95f2\u7684\u5976\u725b\u5b89\u6392\u51fa\u6765\u503c\u73ed\uff0e\u800c\u4e14\uff0c\u6bcf\u4e2a\u65f6\u95f4\u6bb5\u5fc5\u9700\u6709\u5976\u725b\u5728\u503c\u73ed\uff0e&nbsp;&nbsp;\u90a3\u4e48\uff0c\u6700\u5c11\u9700\u8981\u52a8\u7528\u591a\u5c11\u5976\u725b\u53c2\u4e0e\u503c\u73ed\u5462\uff1f\u5982\u679c\u6ca1\u6709\u529e\u6cd5\u5b89\u6392\u51fa\u5408\u7406\u7684\u65b9\u6848\uff0c\u5c31\u8f93\u51fa-1.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Input\"><\/span>Input<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u7b2c1\u884c\uff1aN\uff0cT\uff0e<br> \u00a0\u00a0\u00a0\u00a0\u7b2c2\u5230N+1\u884c\uff1aSi\uff0cEi\uff0e<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Output\"><\/span>Output<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\u6700\u5c11\u5b89\u6392\u7684\u5976\u725b\u6570\uff0e<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Sample_Input\"><\/span>Sample Input<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>3 10<br>1 7<br>3 6<br>6 10<br><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Sample_Output\"><\/span>Sample Output<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>2<\/p>\n\n\n\n<p>\u6837\u4f8b\u8bf4\u660e<br>\u5976\u725b1\u548c\u5976\u725b3\u53c2\u4e0e\u503c\u73ed\u5373\u53ef\uff0e<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"HINT\"><\/span>HINT<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u6392\u5e8f\u540e\u8d2a\u5fc3<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include&lt;map>\n#include&lt;cmath>\n#include&lt;queue>\n#include&lt;cstdio>\n#include&lt;cstring>\n#include&lt;iostream>\n#include&lt;algorithm>\nusing namespace std;\n#define N 25010\nstruct qaz{int l,r;}a&#91;N];\nbool cmp(qaz a, qaz b){return a.l==b.l?a.r&lt;b.r:a.l&lt;b.l;}\nint n,T,now,cnt,tmp,ans;\nint main()\n{\n    scanf(\"%d%d\",&amp;n,&amp;T);\n    for(int i=1;i&lt;=n;i++) scanf(\"%d%d\",&amp;a&#91;i].l,&amp;a&#91;i].r);\n    sort(a+1,a+n+1,cmp);\n    while(now&lt;T)\n    {\n        tmp=now;\n        while(cnt&lt;n&amp;&amp;a&#91;cnt+1].l&lt;=tmp+1){cnt++;now=max(now,a&#91;cnt].r);}\n        if((cnt==n&amp;&amp;a&#91;cnt].r&lt;T)||(a&#91;cnt+1].l>now+1)){puts(\"-1\");return 0;}\n        ans++;\n    }\n    now&lt;T?puts(\"-1\"):printf(\"%d\\n\",ans);\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>3389: [Usaco2004 Dec]Cleaning Shifts\u5b89\u6392\u503c\u73ed Time Limit:&#038;nb [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,66],"tags":[6],"class_list":["post-622","post","type-post","status-publish","format-standard","hentry","category-bzoj","category-usaco","tag-6"],"_links":{"self":[{"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts\/622","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=622"}],"version-history":[{"count":1,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts\/622\/revisions"}],"predecessor-version":[{"id":623,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts\/622\/revisions\/623"}],"wp:attachment":[{"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=622"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=622"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=622"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}