{"id":413,"date":"2017-03-29T19:42:34","date_gmt":"2017-03-29T11:42:34","guid":{"rendered":"http:\/\/kylelv.com\/?p=413"},"modified":"2018-01-02T12:15:41","modified_gmt":"2018-01-02T04:15:41","slug":"bzoj-1670-usaco2006-octbuilding-the-moat%e6%8a%a4%e5%9f%8e%e6%b2%b3%e7%9a%84%e6%8c%96%e6%8e%98-%e5%87%b8%e5%8c%85","status":"publish","type":"post","link":"https:\/\/blog.kylelv.com\/?p=413","title":{"rendered":"bzoj 1670: [Usaco2006 Oct]Building the Moat\u62a4\u57ce\u6cb3\u7684\u6316\u6398  &#8212; \u51f8\u5305"},"content":{"rendered":"<p>&nbsp;<\/p>\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-69fdeef34c466\" 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-69fdeef34c466\"  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=413\/#1670_Usaco2006_OctBuilding_the_Moat%E6%8A%A4%E5%9F%8E%E6%B2%B3%E7%9A%84%E6%8C%96%E6%8E%98\" title=\"1670: [Usaco2006 Oct]Building the Moat\u62a4\u57ce\u6cb3\u7684\u6316\u6398\">1670: [Usaco2006 Oct]Building the Moat\u62a4\u57ce\u6cb3\u7684\u6316\u6398<\/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=413\/#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=413\/#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=413\/#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=413\/#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=413\/#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=413\/#HINT\" title=\"HINT\">HINT<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/blog.kylelv.com\/?p=413\/#Source\" title=\"Source\">Source<\/a><\/li><\/ul><\/nav><\/div>\n<h2 style=\"text-align: center;\"><span class=\"ez-toc-section\" id=\"1670_Usaco2006_OctBuilding_the_Moat%E6%8A%A4%E5%9F%8E%E6%B2%B3%E7%9A%84%E6%8C%96%E6%8E%98\"><\/span>1670: [Usaco2006 Oct]Building the Moat\u62a4\u57ce\u6cb3\u7684\u6316\u6398<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: center;\"><span class=\"green\">Time Limit:\u00a03 Sec\u00a0\u00a0Memory Limit:\u00a064 MB<\/span><\/p>\n<h2><span class=\"ez-toc-section\" id=\"Description\"><\/span>Description<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<div class=\"content\">\n<p>\u4e3a\u4e86\u9632\u6b62\u53e3\u6e34\u7684\u98df\u8681\u517d\u8fdb\u5165\u4ed6\u7684\u519c\u573a\uff0cFarmer John\u51b3\u5b9a\u5728\u4ed6\u7684\u519c\u573a\u5468\u56f4\u6316\u4e00\u6761\u62a4\u57ce\u6cb3\u3002\u519c\u573a\u91cc\u4e00\u5171\u6709N(8&lt;=N&lt;=5,000)\u80a1\u6cc9\u6c34\uff0c\u5e76\u4e14\uff0c\u62a4\u57ce\u6cb3\u603b\u662f\u7b14\u76f4\u5730\u8fde\u63a5\u5728\u6cb3\u9053\u4e0a\u7684\u76f8\u90bb\u7684\u4e24\u80a1\u6cc9\u6c34\u3002\u62a4\u57ce\u6cb3\u5fc5\u987b\u80fd\u4fdd\u62a4\u6240\u6709\u7684\u6cc9\u6c34\uff0c\u4e5f\u5c31\u662f\u8bf4\uff0c\u80fd\u5305\u56f4\u6240\u6709\u7684\u6cc9\u6c34\u3002\u6cc9\u6c34\u4e00\u5b9a\u5728\u62a4\u57ce\u6cb3\u7684\u5185\u90e8\uff0c\u6216\u8005\u6070\u597d\u5728\u6cb3\u9053\u4e0a\u3002\u5f53\u7136\uff0c\u62a4\u57ce\u6cb3\u6784\u6210\u4e00\u4e2a\u5c01\u95ed\u7684\u73af\u3002 \u6316\u62a4\u57ce\u6cb3\u662f\u4e00\u9879\u6602\u8d35\u7684\u5de5\u7a0b\uff0c\u4e8e\u662f\uff0c\u8282\u7ea6\u7684FJ\u5e0c\u671b\u62a4\u57ce\u6cb3\u7684\u603b\u957f\u5ea6\u5c3d\u91cf\u5c0f\u3002\u8bf7\u4f60\u5199\u4e2a\u7a0b\u5e8f\u8ba1\u7b97\u4e00\u4e0b\uff0c\u5728\u6ee1\u8db3\u9700\u6c42\u7684\u6761\u4ef6\u4e0b\uff0c\u62a4\u57ce\u6cb3\u7684\u603b\u957f\u6700\u5c0f\u662f\u591a\u5c11\u3002 \u6240\u6709\u6cc9\u6c34\u7684\u5750\u6807\u90fd\u5728\u8303\u56f4\u4e3a(1..10,000,000,1..10,000,000)\u7684\u6574\u70b9\u4e0a\uff0c\u4e00\u80a1\u6cc9\u6c34\u5bf9\u5e94\u7740\u4e00\u4e2a\u552f\u4e00\u786e\u5b9a\u7684\u5750\u6807\u3002\u5e76\u4e14\uff0c\u4efb\u610f\u4e09\u80a1\u6cc9\u6c34\u90fd\u4e0d\u5728\u4e00\u6761\u76f4\u7ebf\u4e0a\u3002 \u4ee5\u4e0b\u662f\u4e00\u5e45\u5305\u542b20\u80a1\u6cc9\u6c34\u7684\u5730\u56fe\uff0c\u6cc9\u6c34\u7528&#8221;*&#8221;\u8868\u793a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.lydsy.com\/JudgeOnline\/upload\/201409\/111.jpg\" alt=\"\" width=\"325\" height=\"387\" \/><br \/>\n\u56fe\u4e2d\u7684\u76f4\u7ebf\uff0c\u4e3a\u62a4\u57ce\u6cb3\u7684\u6700\u4f18\u6316\u6398\u65b9\u6848\uff0c\u5373\u80fd\u56f4\u4f4f\u6240\u6709\u6cc9\u6c34\u7684\u6700\u77ed\u8def\u7ebf\u3002 \u8def\u7ebf\u4ece\u5de6\u4e0a\u89d2\u8d77\uff0c\u7ecf\u8fc7\u6cc9\u6c34\u7684\u5750\u6807\u4f9d\u6b21\u662f\uff1a(18,0),(6,-6),(0,-5),(-3,-3),(-17,0),(-7,7),(0,4),(3,3)\u3002\u7ed5\u884c\u4e00\u5468\u7684\u8def\u5f84\u603b\u957f\u4e3a70.8700576850888(&#8230;)\u3002\u7b54\u6848\u53ea\u9700\u8981\u4fdd\u7559\u4e24\u4f4d\u5c0f\u6570\uff0c\u4e8e\u662f\u8f93\u51fa\u662f70.87\u3002<\/p>\n<p>&nbsp;<\/p>\n<\/div>\n<h2><span class=\"ez-toc-section\" id=\"Input\"><\/span>Input<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<div class=\"content\">\n<p>* \u7b2c1\u884c: \u4e00\u4e2a\u6574\u6570\uff0cN * \u7b2c2..N+1\u884c: \u6bcf\u884c\u5305\u542b2\u4e2a\u7528\u7a7a\u683c\u9694\u5f00\u7684\u6574\u6570\uff0cx[i]\u548cy[i]\uff0c\u5373\u7b2ci\u80a1\u6cc9\u6c34\u7684\u4f4d \u7f6e\u5750\u6807<\/p>\n<\/div>\n<h2><span class=\"ez-toc-section\" id=\"Output\"><\/span>Output<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<div class=\"content\">\n<p>* \u7b2c1\u884c: \u8f93\u51fa\u4e00\u4e2a\u6570\u5b57\uff0c\u8868\u793a\u6ee1\u8db3\u6761\u4ef6\u7684\u62a4\u57ce\u6cb3\u7684\u6700\u77ed\u957f\u5ea6\u3002\u4fdd\u7559\u4e24\u4f4d\u5c0f\u6570<\/p>\n<\/div>\n<h2><span class=\"ez-toc-section\" id=\"Sample_Input\"><\/span>Sample Input<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<div class=\"content\"><span class=\"sampledata\">20<br \/>\n2 10<br \/>\n3 7<br \/>\n22 15<br \/>\n12 11<br \/>\n20 3<br \/>\n28 9<br \/>\n1 12<br \/>\n9 3<br \/>\n14 14<br \/>\n25 6<br \/>\n8 1<br \/>\n25 1<br \/>\n28 4<br \/>\n24 12<br \/>\n4 15<br \/>\n13 5<br \/>\n26 5<br \/>\n21 11<br \/>\n24 4<br \/>\n1 8<br \/>\n<\/span><\/div>\n<h2><span class=\"ez-toc-section\" id=\"Sample_Output\"><\/span>Sample Output<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<div class=\"content\"><span class=\"sampledata\">70.87<\/span><\/div>\n<h2><span class=\"ez-toc-section\" id=\"HINT\"><\/span>HINT<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<div class=\"content\"><\/div>\n<h2><span class=\"ez-toc-section\" id=\"Source\"><\/span>Source<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>\u51f8\u5305\uff1a<\/p>\n<p>(1)\u627e\u51fa\u70b9\u96c6p[]\u4e2d\u6700\u5de6\u4e0b\u7684\u70b9p1\uff0c\u628ap1\u540c\u70b9\u96c6\u4e2d\u5176\u4ed6\u5404\u70b9\u7528\u7ebf\u6bb5\u8fde\u63a5\uff0c\u5e76\u8ba1\u7b97\u8fd9\u4e9b\u7ebf\u6bb5\u7684\u659c\u7387\uff0c\u7136\u540e\u6309\u659c\u7387\u4ece\u5c0f\u5230\u5927\u6392\u5e8f\uff0c\u5f97\u5230\u65b0\u7684\u8282\u70b9\u5e8f\u5217p1,p2,&#8230;pn.\u4f9d\u6b21\u8fde\u63a5\u8fd9\u4e9b\u70b9\uff0c\u5f97\u5230\u4e00\u4e2a\u591a\u8fb9\u5f62(\u5df2\u7ecf\u9006\u65f6\u9488\uff0c\u6709\u6240\u8fdb\u5c55\uff0c\u4f46\u8fd8\u9700\u53bb\u6389\u4e0d\u5728\u51f8\u5305\u4e0a\u7684\u70b9)\u3002\u6b64\u65f6p1\u662f\u51f8\u5305\u7684\u8fb9\u754c\u8d77\u70b9\uff0cp2\u548cpn\u4e5f\u662f\u6700\u7ec8\u51f8\u5305\u7684\u9876\u70b9\uff0cp[n+1]=p1(\u770b\u6210\u5faa\u73af\u7684)<\/p>\n<p>(2)\u5220\u9664p3,p4,&#8230;p[n-1]\u4e2d\u4e0d\u5728\u51f8\u5305\u4e0a\u7684\u70b9\uff1a<\/p>\n<p>\u5148\u628ap1,p2,p3\u5165\u6808S\u4e2d\uff0c\u518d\u4f9d\u6b21\u5faa\u73af(i = 3 -&gt; n-1)\uff0c\u82e5\u6808\u9876\u7684\u4e24\u4e2a\u70b9\u548c\u5f53\u524d\u7684\u70b9p[i]\u8fd9\u4e09\u70b9\u8fde\u7ebf\u7684\u65b9\u5411\u5411\u987a\u65f6\u9488\u65b9\u5411\u504f\u8f6c\uff0c\u8868\u660e\u662f\u51f9\u7684\uff0c\u5e94\u5220\u9664\uff0c\u5219\u6808\u9876\u5143\u7d20\u51fa\u6808(\u8981\u5faa\u73af\u5224\u65ad\uff0c\u5373\u53ef\u80fd\u524d\u9762\u7684\u4ecd\u662f\u51f9\u7684\uff0c\u8fd8\u9700\u518d\u51fa\u6808\uff0c\u4e3e\u4f8b\u5982\u4e0b\u56fe)\uff0c\u76f4\u5230\u5411\u9006\u65f6\u9488\u65b9\u5411\u504f\u8f6c\u6216\u8005\u6808\u5185\u53ea\u67092\u4e2a\u5143\u7d20\u4e86(p1p2)\uff0c\u5c31\u628a\u5f53\u524d\u70b9p[i]\u5165\u6808\u3002<\/p>\n<p>\u6700\u540e\u6808\u4e2d\u7684\u5143\u7d20\u5c31\u662f\u6700\u7ec8\u51f8\u5305\u4e0a\u7684\u70b9\u3002<\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/hi.csdn.net\/attachment\/201202\/16\/0_1329376136khp1.gif\" alt=\"\" width=\"461\" height=\"362\" \/><\/p>\n<p>\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/hi.csdn.net\/attachment\/201202\/16\/0_13293761544n4b.gif\" alt=\"\" width=\"455\" height=\"357\" \/><\/p>\n<p>\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/hi.csdn.net\/attachment\/201202\/16\/0_1329376174qpZH.gif\" alt=\"\" width=\"458\" height=\"359\" \/><\/p>\n<p>\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d<\/p>\n<pre class=\"lang:c++ decode:true \">#include&lt;map&gt;\r\n#include&lt;cmath&gt;\r\n#include&lt;queue&gt;\r\n#include&lt;cstdio&gt;\r\n#include&lt;cstring&gt;\r\n#include&lt;iostream&gt;\r\n#include&lt;algorithm&gt;\r\nusing namespace std;\r\n#define ll long long\r\n#define db double\r\n#define N 5050\r\n#define inf 100000009\r\nchar xB[1&lt;&lt;15],*xS=xB,*xTT=xB;\r\n#define getc() (xS==xTT&amp;&amp;(xTT=(xS=xB)+fread(xB,1,1&lt;&lt;15,stdin),xS==xTT)?0:*xS++)\r\n#define isd(c) (c&gt;='0'&amp;&amp;c&lt;='9')\r\ninline int read(){\r\n    char xchh;\r\n    int xaa;\r\n    while(xchh=getc(),!isd(xchh));(xaa=xchh-'0');\r\n    while(xchh=getc(),isd(xchh))xaa=xaa*10+xchh-'0';return xaa;\r\n}\r\nstruct tb{db x,y,k;}p[N],s[N];\r\nbool cmp(tb a,tb b){return a.k&lt;b.k;}\r\ndb mul(tb a,tb b,tb c){return (a.x-c.x)*(b.y-c.y)-(b.x-c.x)*(a.y-c.y);}\r\ndb dis(tb a,tb b){return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));}\r\nint n,x,y,tp=1;\r\ndb ans;\r\nint main()\r\n{\r\n    n=read();\r\n    for(int i=0;i&lt;n;i++)\r\n    {\r\n        x=read();y=read();\r\n        p[i]=(tb){(db)x,(db)y};\r\n        if(x&lt;p[0].x||(x==p[0].x&amp;&amp;y&lt;p[0].y)) swap(p[0],p[i]); \r\n    }\r\n    for(int i=0;i&lt;n;i++) p[i].k=(p[i].x==p[0].x?inf:(p[i].y-p[0].y)\/(p[i].x-p[0].x));\r\n    sort(p+1,p+n,cmp);\r\n    p[n]=p[0];s[0]=p[0];s[1]=p[1];\r\n    for(int i=2;i&lt;=n;i++)\r\n    {\r\n        while(tp&amp;&amp;mul(p[i],s[tp],s[tp-1])&gt;=0) tp--;\r\n        s[++tp]=p[i];\r\n    }\r\n    for(int i=0;i&lt;tp;i++) ans+=dis(s[i],s[i+1]);\r\n    printf(\"%.2lf\\n\",ans);\r\n    return 0;\r\n}<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; 1670: [Usaco2006 Oct]Building the Moat\u62a4\u57ce\u6cb3\u7684\u6316\u6398 Tim [&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],"tags":[28,8,19],"class_list":["post-413","post","type-post","status-publish","format-standard","hentry","category-bzoj","tag-28","tag-8","tag-19"],"_links":{"self":[{"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts\/413","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=413"}],"version-history":[{"count":3,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts\/413\/revisions"}],"predecessor-version":[{"id":416,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts\/413\/revisions\/416"}],"wp:attachment":[{"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=413"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=413"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=413"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}