{"id":999,"date":"2014-10-02T13:27:27","date_gmt":"2014-10-02T05:27:27","guid":{"rendered":"http:\/\/www.shuizilong.com\/house\/?p=999"},"modified":"2016-08-24T19:33:57","modified_gmt":"2016-08-24T11:33:57","slug":"2013-acmicpc-asia-regional-hangzhou-onsite","status":"publish","type":"post","link":"https:\/\/www.shuizilong.com\/house\/archives\/2013-acmicpc-asia-regional-hangzhou-onsite\/","title":{"rendered":"2013 ACM\/ICPC Asia Regional Hangzhou Onsite"},"content":{"rendered":"<p><a href=\"http:\/\/acmicpc.info\/archives\/1636\">http:\/\/acmicpc.info\/archives\/1636<\/a><\/p>\n<p><!--more--><\/p>\n<h2>Problem A. Lights Against Dudely<\/h2>\n<h3>Brief description: <\/h3>\n<p><quote> There are at most fifteen vulnerable rooms in the bank.<\/quote><\/p>\n<h3>Analysis: <\/h3>\n<p>\u679a\u4e3e + \u72b6\u6001\u538b\u7f29 DP\u3002<\/p>\n<pre class=\"brush: cpp; light: false; title: ; toolbar: true; notranslate\" title=\"\">\r\n\/\/}\/* .................................................................................................................................. *\/\r\n\r\nconst int dx&#x5B;] = {-1, 0, 1, 0, -1};\r\nconst int dy&#x5B;] = {0, 1, 0, -1, 0};\r\n\r\nconst int NN = 15, N = 209;\r\nchar Map&#x5B;N]&#x5B;N]; int id&#x5B;N]&#x5B;N]; int dp&#x5B;1&lt;&lt;NN];\r\nint n, m, nn;\r\n\r\nbool inGrid(int x, int y){\r\n    return x &gt;= 0 &amp;&amp; y &gt;= 0 &amp;&amp; x &lt; n &amp;&amp; y &lt; m;\r\n}\r\n\r\nstruct rec{\r\n    int x, y, s;\r\n    rec(int x = 0, int y = 0):x(x),y(y){\r\n    }\r\n    void init(int o = 0){\r\n        s = _1(id&#x5B;x]&#x5B;y]);\r\n        REP(d, 2){\r\n            int xx = x + dx&#x5B;o+d], yy = y + dy&#x5B;o+d];\r\n            if (!inGrid(xx, yy)) continue;\r\n            if (Map&#x5B;xx]&#x5B;yy] == '.') s |= _1(id&#x5B;xx]&#x5B;yy]);\r\n            else{\r\n                s = 0;\r\n                return;\r\n            }\r\n        }\r\n    }\r\n} A&#x5B;NN];\r\n\r\nint f(int id, int off){\r\n\r\n    REP(i, nn){\r\n        if (i == id) A&#x5B;i].init(off);\r\n        else A&#x5B;i].init();\r\n    }\r\n\r\n    FLC(dp, 0x3f); dp&#x5B;0] = 0;\r\n    REP(s, _1(nn)){\r\n        REP(i, nn) if (!_1(s, i)){\r\n            int ss = s | A&#x5B;i].s;\r\n            checkMin(dp&#x5B;ss], dp&#x5B;s] + 1);\r\n        }\r\n    }\r\n    return dp&#x5B;_U(nn)];\r\n}\r\n\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\r\n    while (RD(n, m)){\r\n        REP(i, n) RS(Map&#x5B;i]);\r\n        nn = 0; REP_2(i, j, n, m) if (Map&#x5B;i]&#x5B;j] == '.'){\r\n            id&#x5B;i]&#x5B;j] = nn;\r\n            A&#x5B;nn++] = rec(i, j);\r\n        }\r\n\r\n        if (!nn){\r\n            OT(0);\r\n            continue;\r\n        }\r\n\r\n        int res = INF; REP(i, nn) REP(d, 4){\r\n            checkMin(res, f(i, d));\r\n        }\r\n        if (res == INF) res = -1;\r\n        OT(res);\r\n    }\r\n}\r\n<\/pre>\n<h2>Problem F. Infinite Go<\/h2>\n<h3>Brief description: <\/h3>\n<p>\u9898\u76ee\u610f\u601d\u5c31\u662f\u7ed9\u4f60\u4e0b\u56f4\u68cb\u7684\u4f4d\u7f6e\uff0c\u9ed1\u5b50\u5148\u4e0b\uff0c\u9ed1\u767d\u5b50\u4ea4\u66ff\u7684\u4e0b\uff0c\u9014\u4e2d\u4f1a\u51fa\u73b0\u68cb\u5b50\u88ab\u5403\u6389\u7684\u60c5\u51b5\uff0c\u8ba9\u4f60\u8f93\u51fa\u6700\u540e\u9ed1\u8272\u548c\u767d\u8272\u7684\u68cb\u5b50\u5404\u6709\u591a\u5c11\u4e2a\u3002<br \/>\n\u68cb\u5b50\u88ab\u5403\u6389\u7684\u6761\u4ef6\u662f\uff1a\u4e0a\u4e0b\u5de6\u53f3\u56db\u4e2a\u65b9\u5411\u76f8\u90bb\u7684\u540c\u8272\u7684\u68cb\u5b50\u6240\u5f62\u6210\u7684\u7684\u8054\u901a\u5feb\u7684\u8fb9\u7f18\u6ca1\u6709\u7a7a\u4f4d\uff08\u76ee\uff09\u3002\u7a7a\u4f4d\u53ea\u9700\u8981\u8003\u8651\u4e0a\u4e0b\u5de6\u53f3\u56db\u4e2a\u65b9\u5411\u3002<\/p>\n<h3>Analysis: <\/h3>\n<p>\u5e76\u67e5\u96c6\u7ef4\u62a4\u68cb\u5b50\u6240\u5728\u7684\u8054\u901a\u5757\uff0cf[] \u7ef4\u62a4 \u201c\u76ee\u201d\u3002<br \/>\n\u6518\u5916\u5fc5\u5148\u5b89\u5185\uff0c\u5f53\u52a0\u5165\u65b0\u68cb\u5b50\u65f6\uff0c\u5e94\u4e25\u683c\u6309\u7167\uff0c\u5148\u7ef4\u62a4\u81ea\u8eab\u76ee\u6570\uff0c\u518d\u5904\u7406\u5403\u5bf9\u9762\u7684\u60c5\u51b5\uff0c\u518d\u5904\u7406\u5408\u5e76\uff0c\u518d\u8003\u8651\u662f\u5426\u81ea\u8eab\u88ab\u5403\u56db\u4e2a\u6b65\u9aa4\u3002\u3002\u3002<br \/>\n\uff08\u5148\u51fa\u57fa\u672c\u88c5\u3001Gank \u4e00\u6ce2\uff0c\u518d\u548c\u961f\u53cb\u62b1\u56e2\u3002\u3002\uff09\u3002\u3002\u3002<\/p>\n<pre class=\"brush: cpp; light: false; title: ; toolbar: true; notranslate\" title=\"\">\r\n\r\n\/\/}\/* .................................................................................................................................. *\/\r\n\r\nconst int N = int(1e4) + 9;\r\nmap&lt;PII, int&gt; B; \/\/ Board\r\nint x&#x5B;N], y&#x5B;N], f&#x5B;N], p&#x5B;N];\r\nint n, n1, n2;\r\n\r\nint Find(int x){\r\n    return p&#x5B;x] == x ? x : p&#x5B;x] = Find(p&#x5B;x]);\r\n}\r\n\r\nvoid Union(int x, int y){\r\n    x = Find(x), y = Find(y); if (x == y) return;\r\n    p&#x5B;x] = y; f&#x5B;y] += f&#x5B;x];\r\n}\r\n\r\nvoid del(int n){\r\n    if (n&amp;1) --n2; else --n1; B.erase(MP(x&#x5B;n], y&#x5B;n]));\r\n    REP(d, 4){\r\n        int xx = x&#x5B;n] + dx&#x5B;d], yy = y&#x5B;n] + dy&#x5B;d];\r\n        if (!xx || !yy || !CTN(B, MP(xx, yy))) continue;\r\n        int m = B&#x5B;MP(xx, yy)];\r\n        if ((n^m)&amp;1) ++f&#x5B;Find(m)]; else del(m);\r\n    }\r\n}\r\n\r\nvoid print(){\r\n    FOR_1(a, 1, 10){\r\n        FOR_1(b, 1, 10){\r\n            if (!CTN(B, MP(a, b))) putchar('.');\r\n            else putchar(B&#x5B;MP(a, b)]&amp;1 ? '&amp;' : '*');\r\n        }\r\n        puts(&quot;&quot;);\r\n    }\r\n    puts(&quot;&quot;);\r\n}\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\r\n    Rush{\r\n        CLR(B), n = n1 = n2 = 0; Rush{\r\n            RD(x&#x5B;n], y&#x5B;n]); p&#x5B;n] = B&#x5B;MP(x&#x5B;n], y&#x5B;n])] = n; f&#x5B;n] = 0;\r\n            if (n&amp;1) ++n2; else ++n1;\r\n\r\n            REP(d, 4){\r\n                int xx = x&#x5B;n] + dx&#x5B;d], yy = y&#x5B;n] + dy&#x5B;d];\r\n                if (!xx || !yy || CTN(B, MP(xx, yy))) continue;\r\n                ++f&#x5B;n];\r\n            }\r\n            REP(d, 4){\r\n                int xx = x&#x5B;n] + dx&#x5B;d], yy = y&#x5B;n] + dy&#x5B;d];\r\n                if (!xx || !yy || !CTN(B, MP(xx, yy))) continue;\r\n                int m = Find(B&#x5B;MP(xx, yy)]);\r\n                --f&#x5B;m]; if ((m^n)&amp;1 &amp;&amp; !f&#x5B;m]) del(m);\r\n            }\r\n            REP(d, 4){\r\n                int xx = x&#x5B;n] + dx&#x5B;d], yy = y&#x5B;n] + dy&#x5B;d];\r\n                if (!xx || !yy || !CTN(B, MP(xx, yy))) continue;\r\n                int m = Find(B&#x5B;MP(xx, yy)]);\r\n                if (!((m^n)&amp;1)) Union(m, n);\r\n            }\r\n\r\n            if (!f&#x5B;Find(n)]) del(n);\r\n\r\n            ++n;\r\n        }\r\n        printf(&quot;%d %d\\n&quot;, n1, n2);\r\n    }\r\n}\r\n\r\n<\/pre>\n<h2>Problem G. Ants<\/h2>\n<p>fork: <a href=\"https:\/\/www.shuizilong.com\/house\/archives\/poj-3764-the-xor-longest-path\/\">https:\/\/www.shuizilong.com\/house\/archives\/poj-3764-the-xor-longest-path\/<\/a><\/p>\n<p><a href=\"http:\/\/acm.hust.edu.cn\/vjudge\/problem\/viewSource.action?id=2818548\">http:\/\/acm.hust.edu.cn\/vjudge\/problem\/viewSource.action?id=2818548<\/a><\/p>\n<h2>Problem H. Rabbit Kingdom<\/h2>\n<h3>Brief description: <\/h3>\n<p>\u7ed9\u51fa n \u4e2a\u6570\uff0c\u6709 m \u4e2a\u67e5\u8be2\uff0c\u6bcf\u6b21\u67e5\u8be2\u8be2\u95ee\u533a\u95f4 [L, R] \u4e2d\u6700\u591a\u6709\u591a\u5c11\u4e2a\u6570\u4e0e\u533a\u95f4\u4e2d\u5176\u4ed6\u6570\u90fd\u4e0d\u4e92\u8d28\u3002<\/p>\n<h3>Analysis: <\/h3>\n<p>\u79bb\u7ebf + \u6811\u72b6\u6570\u7ec4\u3002\uff08\u7c7b\u4f3c Dquery\uff09<\/p>\n<pre class=\"brush: cpp; light: false; title: ; toolbar: true; notranslate\" title=\"\">\r\n\r\n\/\/}\/* .................................................................................................................................. *\/\r\n\r\nconst int N = int(2e5) + 9;\r\nint n;\r\n\r\nnamespace BIT{\r\n    typedef int intt;\r\n    intt C&#x5B;N], S;\r\n    void Add(int x, int d){\r\n        if (!x) return;\r\n        for (;x&lt;=n;x+=low_bit(x)) C&#x5B;x] += d;\r\n        S += d;\r\n    }\r\n    intt Sum(int x){\r\n        intt res = 0; for (;x;x^=low_bit(x)) res += C&#x5B;x];\r\n        return res;\r\n    }\r\n    intt Sum(int l, int r){\r\n        return Sum(r) - Sum(l-1);\r\n    }\r\n} using namespace BIT;\r\n\r\n\/\/\u6700\u5c0f\u7d20\u56e0\u5b50\u3002\u3002\r\nconst int PMAX = N;\r\nVI P; bitset&lt;PMAX&gt; isC; int p&#x5B;PMAX];\r\n#define ii (i*P&#x5B;j])\r\nvoid sieve(){\r\n    FOR(i, 2, PMAX){\r\n        if (!isC&#x5B;i]) P.PB(i),p&#x5B;i]=i;\r\n        for (int j=0;j&lt;SZ(P)&amp;&amp;ii&lt;PMAX;++j){\r\n            isC&#x5B;ii]=1; p&#x5B;ii]=P&#x5B;j]; if (!(i%P&#x5B;j])) break;\r\n        }\r\n    }\r\n}\r\n#undef ii\r\n\r\nint A&#x5B;N], suc&#x5B;N], prd&#x5B;N], last&#x5B;N];\r\nVII qry&#x5B;N], rls&#x5B;N]; int res&#x5B;N];\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\r\n    sieve();\r\n\r\n    int q; while (RD(n, q)){\r\n\r\n        RST(C); S = 0; REP_1(i, n) RD(A&#x5B;i]), CLR(qry&#x5B;i], rls&#x5B;i]);\r\n\r\n        REP(i, q){\r\n            int l, r; RD(l, r);\r\n            qry&#x5B;r].PB(MP(l, i));\r\n        }\r\n\r\n        RST(last); REP_1(i, n){\r\n            int x = A&#x5B;i]; prd&#x5B;i] = 0;\r\n            while (x != 1){\r\n                int px = p&#x5B;x]; checkMax(prd&#x5B;i], last&#x5B;px]); last&#x5B;px] = i;\r\n                do x \/= px; while (p&#x5B;x] == px);\r\n            }\r\n        }\r\n\r\n        FLC(last, 0x3f); DWN_1(i, n, 1){\r\n            int x = A&#x5B;i]; suc&#x5B;i] = INF;\r\n            while (x != 1){\r\n                int px = p&#x5B;x]; checkMin(suc&#x5B;i], last&#x5B;px]);\r\n                last&#x5B;px] = i;\r\n                do x \/= px; while (p&#x5B;x] == px);\r\n            }\r\n        }\r\n\r\n        REP_1(i, n) if (suc&#x5B;i] == INF) suc&#x5B;i] = 0;\r\n\r\n        REP_1(i, n){\r\n\r\n            Add(i, 1); A&#x5B;i] = 1; int l = prd&#x5B;i], r = suc&#x5B;i];\r\n\r\n            Add(l, -1);\r\n            rls&#x5B;r].PB(MP(i, -1));\r\n            rls&#x5B;r].PB(MP(l, 1));\r\n\r\n            ECH(it, rls&#x5B;i]){\r\n                Add(it-&gt;fi, it-&gt;se);\r\n            }\r\n\r\n            ECH(it, qry&#x5B;i]){\r\n                int l = it-&gt;fi, id = it-&gt;se;\r\n                res&#x5B;id] = S - BIT::Sum(l-1);\r\n            }\r\n\r\n            \/\/REP_1(i, n) cout &lt;&lt; Sum(i, i) &lt;&lt; &quot; &quot;; puts(&quot;&quot;);\r\n        }\r\n        \/\/puts(&quot;&quot;);\r\n        REP(i, q) OT(res&#x5B;i]);\r\n    }\r\n}\r\n\r\n\r\n<\/pre>\n<h2>Problem I. Gems Fight!<\/h2>\n<h3>Brief description: <\/h3>\n<p>\u7565\u3002\uff09<\/p>\n<h3>Analysis: <\/h3>\n<p>\u72b6\u6001\u538b\u7f29 + \u535a\u5f08 DP\u3002<\/p>\n<p>\uff08\u4e3b\u8981\u662f The Gems collected are stored in a <font color=\"red\">shared cooker<\/font>.<br \/>\n\u5982\u679c\u6ca1\u6709\u8fd9\u4e2a\u6761\u4ef6\u3002\u3002\u72b6\u6001\u5c06\u4f1a\u6709\u540e\u6548\u6027\u3002\u3002\u53ea\u80fd\u641c\uff1f\uff09<\/p>\n<pre class=\"brush: cpp; light: false; title: ; toolbar: true; notranslate\" title=\"\">\r\n\r\n\/\/}\/* .................................................................................................................................. *\/\r\n\r\nconst int N = 21, M = 9;\r\nint F&#x5B;1&lt;&lt;N], S&#x5B;1&lt;&lt;N], n, m, s0;\r\n\r\nvoid init(){\r\n\r\n    VVI I; REP(i, n){\r\n        VI t; Rush t.PB(RD()-1);\r\n        I.PB(t);\r\n    }\r\n\r\n    static int cnt&#x5B;M]; REP(s, _1(n)){\r\n        RST(cnt); REP(i, n) if (_1(s, i)) ECH(it, I&#x5B;i]) ++cnt&#x5B;*it];\r\n        S&#x5B;s] = 0; REP(i, m) S&#x5B;s] += cnt&#x5B;i] \/ s0;\r\n    }\r\n\r\n    FLC(F, -1);\r\n}\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\r\n    while (RD(m,n,s0)){\r\n\r\n        init(); FLC(F, 0x8f); F&#x5B;_U(n)] = 0; DWN(s, _1(n), 1){\r\n            REP(i, n) if (_1(s, i)){\r\n                int ss = s ^ _1(i), d = S&#x5B;s]-S&#x5B;ss];\r\n                if (d) checkMax(F&#x5B;ss], F&#x5B;s] + d);\r\n                else checkMax(F&#x5B;ss], -F&#x5B;s]);\r\n            }\r\n        }\r\n\r\n        OT(F&#x5B;0]);\r\n    }\r\n}\r\n\r\n<\/pre>\n<h2>Problem K. Candy Factory<\/h2>\n<h3>Brief description: <\/h3>\n<p>\u7565\u3002\uff09<\/p>\n<h3>Analysis: <\/h3>\n<p>\u7f51\u7edc\u6d41<\/p>\n<p>\u5efa\u6a21 1\uff1a\u4e0a\u4e0b\u754c\u6700\u5c0f\u8d39\u7528\u6d41<br \/>\n<code>S -> M -> C0 <-> C1 -> T<\/code><br \/>\n<a href=\"http:\/\/acm.hust.edu.cn\/vjudge\/problem\/viewSource.action?id=2823256\">http:\/\/acm.hust.edu.cn\/vjudge\/problem\/viewSource.action?id=2823256<\/a><\/p>\n<p>\u5efa\u6a21 2\uff1a\u6700\u5c0f\u8d39\u7528\u6700\u5927\u6d41<br \/>\n<code>S -> M -> C0 -> C1 -> T<\/code><br \/>\n<code>S ------> C2 -> C1 -> T<\/code><br \/>\n<a href=\"http:\/\/acm.hust.edu.cn\/vjudge\/problem\/viewSource.action?id=2822981\">http:\/\/acm.hust.edu.cn\/vjudge\/problem\/viewSource.action?id=2822981<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>http:\/\/acmicpc.info\/archives\/1636<\/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":[164],"tags":[],"class_list":["post-999","post","type-post","status-publish","format-standard","hentry","category-onsite"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p2tdP7-g7","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/999","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=999"}],"version-history":[{"count":1,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/999\/revisions"}],"predecessor-version":[{"id":1000,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/999\/revisions\/1000"}],"wp:attachment":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/media?parent=999"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/categories?post=999"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/tags?post=999"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}