{"id":1979,"date":"2022-07-05T15:23:16","date_gmt":"2022-07-05T07:23:16","guid":{"rendered":"https:\/\/www.shuizilong.com\/house\/?p=1979"},"modified":"2022-07-05T15:23:16","modified_gmt":"2022-07-05T07:23:16","slug":"luogu-p4043-ahoi2014-jsoi2014%e6%94%af%e7%ba%bf%e5%89%a7%e6%83%85","status":"publish","type":"post","link":"https:\/\/www.shuizilong.com\/house\/archives\/luogu-p4043-ahoi2014-jsoi2014%e6%94%af%e7%ba%bf%e5%89%a7%e6%83%85\/","title":{"rendered":"Luogu P4043. [AHOI2014\/JSOI2014]\u652f\u7ebf\u5267\u60c5"},"content":{"rendered":"<ul>\n<li><a href=\"https:\/\/www.luogu.com.cn\/problem\/P4043\">https:\/\/www.luogu.com.cn\/problem\/P4043<\/a><\/li>\n<li><a href=\"https:\/\/darkbzoj.cc\/problem\/3876\">https:\/\/darkbzoj.cc\/problem\/3876<\/a><\/li>\n<li><a href=\"https:\/\/blog.bill.moe\/AHOI2014-plot\/\">https:\/\/blog.bill.moe\/AHOI2014-plot\/<\/a><\/li>\n<\/ul>\n<pre class=\"brush: cpp; light: false; title: ; toolbar: true; notranslate\" title=\"\">\r\nconst int N = int(5e3) + 9, M = int(3e2) + 9;\r\n\r\nVI in&#x5B;M], out&#x5B;M];\r\n\r\nstruct Simplex {\r\n    DB a&#x5B;N+1]&#x5B;M+1];\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    int gao() {\r\n        \/\/ z b\r\n        \/\/ c A\r\n        int n, m = 0; RD(n);\r\n\r\n        REP_1(i, n) {\r\n            Rush {\r\n                int j; RD(j); a&#x5B;0]&#x5B;0] += RD(a&#x5B;++m]&#x5B;0]);\r\n                out&#x5B;i].PB(m); in&#x5B;j].PB(m);\r\n            }\r\n        }\r\n\r\n        FOR_1(i, 2, n) {\r\n            a&#x5B;0]&#x5B;i] += SZ(out&#x5B;i]) - SZ(in&#x5B;i]);\r\n            for (auto j: in&#x5B;i]) a&#x5B;j]&#x5B;i] -= 1;\r\n            for (auto j: out&#x5B;i]) a&#x5B;j]&#x5B;i] += 1;\r\n        }\r\n        this-&gt;n = m; this-&gt;m = n;\r\n        return run();\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    OT(fst.gao());\r\n}\r\n\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>https:\/\/www.luogu.com.cn\/problem\/P4043 https:\/\/darkbzoj.cc\/problem\/3876 https:\/\/blog.bill.moe\/AHOI2014-plot\/ const int N = int(5e3) + 9, M = int(3e2) + 9; VI in&#x5B;M], out&#x5B;M]; struct Simplex { DB a&#x5B;N+1]&#x5B;M+1]; int n, m; void pivot(int in, int out) { REP(i, m+1) if(i!=in) a&#x5B;out]&#x5B;i] \/= -a&#x5B;out]&#x5B;in]; \/\/\u91cd\u7f6eout\u7ea6\u675f a&#x5B;out]&#x5B;in] = 1\/a&#x5B;out]&#x5B;in]; REP(i, n+1) if (i!=out &amp;&amp; sgn(a&#x5B;i]&#x5B;in])) { \/\/\u91cd\u65b0\u8ba1\u7b97\u5176\u4ed6\u7ea6\u675f DB t = a&#x5B;i]&#x5B;in]; a&#x5B;i]&#x5B;in] [&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-1979","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p2tdP7-vV","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/1979","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=1979"}],"version-history":[{"count":0,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/1979\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/media?parent=1979"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/categories?post=1979"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/tags?post=1979"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}