{"id":1986,"date":"2022-07-07T05:40:39","date_gmt":"2022-07-06T21:40:39","guid":{"rendered":"https:\/\/www.shuizilong.com\/house\/?p=1986"},"modified":"2022-07-07T07:19:08","modified_gmt":"2022-07-06T23:19:08","slug":"codechef-feb12-flight-distance","status":"publish","type":"post","link":"https:\/\/www.shuizilong.com\/house\/archives\/codechef-feb12-flight-distance\/","title":{"rendered":"Codechef FEB12. Flight Distance"},"content":{"rendered":"<ul>\n<li><a href=\"https:\/\/www.codechef.com\/submit\/FLYDIST\">https:\/\/www.codechef.com\/submit\/FLYDIST<\/a><\/li>\n<\/ul>\n<p>\u975e\u5e38\u66b4\u529b\u7f8e\u5b66\u7684\u7ebf\u6027\u89c4\u5212\u3002\u3002\u3002\u56e7\u3002\u3002\u3002\u4e0d\u77e5\u4e3a\u4f55\uff0c\u8ba9\u6211\u60f3\u8d77 <a href=\"https:\/\/www.shuizilong.com\/house\/archives\/spoj-cake3-delicious-cake\/\">SPOJ CAKE3<\/a>\u3002\u3002\u3002<\/p>\n<p>\u503c\u5f97\u6ce8\u610f\u7684\u4e8b\u3002\u3002\u3002\u9996\u5148\u5206\u6570\u7c7b\u662f\u53ef\u4ee5\u5077\u61d2\u4e0d\u5199\u7684&#8230;\uff08\u66b4\u529b\u679a\u4e3e\u5206\u6bcd\uff09\u3002\u3002\u3002<br \/>\n\u7136\u540e\u4e5f\u6ca1\u5fc5\u8981\u5206 d[][] \u548c w[][] \u8fdb\u884c\u8ba8\u8bba\uff0c\u56e0\u4e3a\u53cd\u6b63\u90fd\u76f8\u7b49\u4e86\u3002\u3002\u3002<br \/>\n\u6700\u540e\u6240\u6709\u7684\u7ea6\u675f\u5173\u7cfb\u6070\u597d\u5c31\u662f\u6240\u6709\u7684\u4e09\u89d2\u4e0d\u7b49\u5f0f\u3002\u3002<br \/>\n\uff08\u4e5f\u5c31\u662f floyd \u7b97\u6cd5\u91cc\u7684 kij\u3001\u4f46\u8fd9\u4e2a\u9898\u91cc\u56e0\u4e3a\u53cd\u6b63\u90fd\u7ea6\u675f\u6761\u4ef6\uff0c\u6240\u4ee5\u4f60\u7ecf\u5178\u987a\u5e8f\u5199\u9519\u7684\u8bdd\u4e5f\u4f1a\u4e0d\u5f71\u54cd\u8ba1\u7b97\u7ed3\u679c\u56e7&#8230; \uff09\u3002\u3002\u3002\u3002<\/p>\n<pre class=\"brush: cpp; light: false; title: ; toolbar: true; notranslate\" title=\"\">\r\nconst int N = 10;\r\nint d&#x5B;N]&#x5B;N], x0&#x5B;N]&#x5B;N], x1&#x5B;N]&#x5B;N];\r\nint n;\r\n\r\nstruct Simplex {\r\n    const static int N = int(1e2) + 9, M = int(1e3) + 9;\r\n    DB a&#x5B;N]&#x5B;M];\r\n    int n, m;\r\n\r\n    void pivot(int in, int out) {\r\n        REP(i, m+1) if(i!=in) a&#x5B;out]&#x5B;i] \/= -a&#x5B;out]&#x5B;in]; \/\/\u91cd\u7f6eout\u7ea6\u675f\r\n        a&#x5B;out]&#x5B;in] = 1\/a&#x5B;out]&#x5B;in];\r\n\r\n        REP(i, n+1) if (i!=out &amp;&amp; sgn(a&#x5B;i]&#x5B;in])) { \/\/\u91cd\u65b0\u8ba1\u7b97\u5176\u4ed6\u7ea6\u675f\r\n            DB t = a&#x5B;i]&#x5B;in]; a&#x5B;i]&#x5B;in] = 0;\r\n            REP(j, m+1) a&#x5B;i]&#x5B;j] += t*a&#x5B;out]&#x5B;j];\r\n        }\r\n    }\r\n\r\n    DB run() {\r\n        while (true) {\r\n            int in=0, out=0; DB Min=OO;\r\n            REP_1(i, m) if(sgn(a&#x5B;0]&#x5B;i])&gt;0) {\r\n                in=i;\r\n                break;\r\n            }\r\n            if(!in)return a&#x5B;0]&#x5B;0];\r\n            REP_1(i, n) if(sgn(a&#x5B;i]&#x5B;in])&lt;0&amp;&amp;a&#x5B;i]&#x5B;0]\/-a&#x5B;i]&#x5B;in]&lt;Min) {\r\n                Min=a&#x5B;i]&#x5B;0]\/-a&#x5B;i]&#x5B;in];\r\n                out=i;\r\n            }\r\n            if(!out)throw ; \/\/unbounded\r\n            pivot(in, out);\r\n        }\r\n    }\r\n\r\n    void gao() {\r\n\r\n        if (RD(::n) == 2) {\r\n            puts(&quot;0\/1&quot;);\r\n            return;\r\n        }\r\n        n = m = 0;\r\n\r\n        REP(i, ::n) FOR(j, i+1, ::n) {\r\n            x0&#x5B;i]&#x5B;j] = x0&#x5B;j]&#x5B;i] = ++n;\r\n            x1&#x5B;i]&#x5B;j] = x1&#x5B;j]&#x5B;i] = ++n;\r\n        }\r\n\r\n\/\/ z b\r\n\/\/ c A\r\n\r\n        Rush {\r\n            int x, y, w; RD(x, y, w);\r\n            d&#x5B;x]&#x5B;y] = d&#x5B;y]&#x5B;x] = w;\r\n            a&#x5B;x0&#x5B;x]&#x5B;y]]&#x5B;0] = a&#x5B;x1&#x5B;x]&#x5B;y]]&#x5B;0] = 1;\r\n        }\r\n\r\n\r\n        REP(k, ::n) REP(i, ::n) FOR(j, i+1, ::n) {\r\n            \/\/ d&#x5B;i]&#x5B;k] + d&#x5B;k]&#x5B;j] &lt;= d&#x5B;i]&#x5B;j]\r\n            ++m;\r\n            a&#x5B;0]&#x5B;m] += d&#x5B;i]&#x5B;j] - d&#x5B;i]&#x5B;k] - d&#x5B;k]&#x5B;j];\r\n            a&#x5B;x0&#x5B;i]&#x5B;j]]&#x5B;m] -= 1; a&#x5B;x1&#x5B;i]&#x5B;j]]&#x5B;m] += 1;\r\n            a&#x5B;x0&#x5B;i]&#x5B;k]]&#x5B;m] += 1; a&#x5B;x1&#x5B;i]&#x5B;k]]&#x5B;m] -= 1;\r\n            a&#x5B;x0&#x5B;k]&#x5B;j]]&#x5B;m] += 1; a&#x5B;x1&#x5B;k]&#x5B;j]]&#x5B;m] -= 1;\r\n        }\r\n\r\n        DB z = run();\r\n        \/\/printf(&quot;%.9f\\n&quot;, z);\r\n        int i = 1; while (sgn(z * i, int(z*i+0.5))) ++i;\r\n        printf(&quot;%d\/%d\\n&quot;,int(z*i+0.5), i);\r\n    }\r\n} fst;\r\n\r\nint main() {\r\n\r\n#ifndef ONLINE_JUDGE\r\n    freopen(&quot;in.txt&quot;, &quot;r&quot;, stdin);\r\n    \/\/freopen(&quot;out.txt&quot;, &quot;w&quot;, stdout);\r\n#endif\r\n    fst.gao();\r\n}\r\n\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>https:\/\/www.codechef.com\/submit\/FLYDIST \u975e\u5e38\u66b4\u529b\u7f8e\u5b66\u7684\u7ebf\u6027\u89c4\u5212\u3002\u3002\u3002\u56e7\u3002\u3002\u3002\u4e0d\u77e5\u4e3a\u4f55\uff0c\u8ba9\u6211\u60f3\u8d77 SPOJ CAKE3\u3002\u3002\u3002 \u503c\u5f97\u6ce8\u610f\u7684\u4e8b\u3002\u3002\u3002\u9996\u5148\u5206\u6570\u7c7b\u662f\u53ef\u4ee5\u5077\u61d2\u4e0d\u5199\u7684&#8230;\uff08\u66b4\u529b\u679a\u4e3e\u5206\u6bcd\uff09\u3002\u3002\u3002 \u7136\u540e\u4e5f\u6ca1\u5fc5\u8981\u5206 d[][] \u548c w[][] \u8fdb\u884c\u8ba8\u8bba\uff0c\u56e0\u4e3a\u53cd\u6b63\u90fd\u76f8\u7b49\u4e86\u3002\u3002\u3002 \u6700\u540e\u6240\u6709\u7684\u7ea6\u675f\u5173\u7cfb\u6070\u597d\u5c31\u662f\u6240\u6709\u7684\u4e09\u89d2\u4e0d\u7b49\u5f0f\u3002\u3002 \uff08\u4e5f\u5c31\u662f floyd \u7b97\u6cd5\u91cc\u7684 kij\u3001\u4f46\u8fd9\u4e2a\u9898\u91cc\u56e0\u4e3a\u53cd\u6b63\u90fd\u7ea6\u675f\u6761\u4ef6\uff0c\u6240\u4ee5\u4f60\u7ecf\u5178\u987a\u5e8f\u5199\u9519\u7684\u8bdd\u4e5f\u4f1a\u4e0d\u5f71\u54cd\u8ba1\u7b97\u7ed3\u679c\u56e7&#8230; \uff09\u3002\u3002\u3002\u3002 const int N = 10; int d&#x5B;N]&#x5B;N], x0&#x5B;N]&#x5B;N], x1&#x5B;N]&#x5B;N]; int n; struct Simplex { const static int N = int(1e2) + 9, M = int(1e3) + 9; DB a&#x5B;N]&#x5B;M]; int n, m; void pivot(int in, int out) { REP(i, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[1],"tags":[],"class_list":["post-1986","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p2tdP7-w2","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/1986","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/comments?post=1986"}],"version-history":[{"count":1,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/1986\/revisions"}],"predecessor-version":[{"id":1987,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/1986\/revisions\/1987"}],"wp:attachment":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/media?parent=1986"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/categories?post=1986"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/tags?post=1986"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}