{"id":136,"date":"2010-08-05T07:40:13","date_gmt":"2010-08-04T23:40:13","guid":{"rendered":"http:\/\/www.shuizilong.com\/house\/?p=136"},"modified":"2012-03-03T08:40:36","modified_gmt":"2012-03-03T00:40:36","slug":"summer-contest-viii-%e6%90%9c%e7%b4%a2%e7%bb%83%e4%b9%a0","status":"publish","type":"post","link":"https:\/\/www.shuizilong.com\/house\/archives\/summer-contest-viii-%e6%90%9c%e7%b4%a2%e7%bb%83%e4%b9%a0\/","title":{"rendered":"Summer Contest VIII. \u641c\u7d22\u7ec3\u4e60"},"content":{"rendered":"<h3>Background :<\/h3>\n<p>\u5199\u603b\u7ed3\uff0c\u603b\u7684\u6765\u8bf4\u4eca\u5929\u9898\u76ee\u5199\u7684\u5f88\u6162\uff0c\u56e0\u4e3a\u8d5b\u524d\u77e5\u9053\u8003\u5bdf\u7684\u8303\u56f4\u662f\u641c\u7d22\uff0c\u6bd5\u7adf\u9664\u4e86\u4e00\u4e9b\u57fa\u672c\u7684\u641c\u7d22\u65b9\u6cd5\u8fd8\u662f\u77e5\u9053\u8fd9\u65b9\u9762\u4e0d\u662f\u5f88\u6709\u5fc3\u5f97\uff0c\u603b\u4e4b\u4eca\u5929\u7684\u6bd4\u8d5b\u6211\u7684\u65f6\u4faf\u76ee\u6807\uff0c\u662f \u201c\u6c42\u4e0d\u4e71\u201d\uff0c\u5728\u4ee3\u7801\u4e0d\u4e71\u7684\u57fa\u7840\u4e0a\u4e89\u53d6\u4e00\u6b21\u7f16\u7801\u901a\u8fc7\uff0c\u4e0d\u8fc7\u770b\u6765\u5440\u4eca\u5929\u7684\u7b56\u7565\u5f88\u6210\u529f\u7684\u5e2e\u52a9\u6211\u62ff\u5230\u4e86\u53c2\u52a0 Summer Contest\u96c6\u8bad\u961f \u7684\u7b2c\u4e00\u4e2aRank I\uff08\u6492\u4e2a\u82b1\u54e6 \\>. < \uff5e\uff09\u3002\u3002\n\n\u5148\u5feb\u901f\u626b\u9898\uff0c\u53d1\u73b0 Problem B\uff0c\u548c Problem C \u90fd\u662f\u505a\u8fc7\u7684\uff0c\u800c\u4e14\u7b2c\u4e09\u9898N\u7687\u540e\u53ef\u4ee5\u5e94\u7528<a href=\"http:\/\/www.matrix67.com\/blog\/article.asp?id=314\">N\u7687\u540e\u95ee\u9898\u4f4d\u8fd0\u7b97\u65b9\u6cd5<\/a>\u5feb\u901f\u7f16\u7801\u5b9e\u73b0\uff0c\u4e8e\u662f\u5148\u62c6\u8fd9\u9898\uff0c11min1A\u3002<br \/>\n\u4e4b\u540e\u8003\u8651\u5148\u5199 Problem A \u8fd8\u662f Problem B\uff0c\u56e0\u4e3a\u90a3\u65f6A\u9898\u6709\u51e0\u4e2a\u7591\u95ee\u7684\u5730\u65b9\uff0c\u51b3\u5b9a\u8fd8\u662f\u52a8\u624b\u5199B\u3002<br \/>\nACM \u7684\u6bd4\u8d5b\u56e0\u4e3a\u6570\u636e\u4f1a\u591a\u7ec4\u4e00\u8d77\u51fa\u73b0\uff0c\u6240\u4ee5\u6362\u5199\u5468\u754c\u641c\u7d22\uff0c\u8fd8\u662f\u6bd4\u8f83\u6709\u628a\u63e1 1h.27min \u51fa\u89e3\u3002<br \/>\n\uff08\u6b64\u9898\u6709\u4e00\u4e2a\u53ef\u80fd\u9020\u6210 PE \u7684\u5730\u65b9\uff0c\u5c31\u662f\u5f53\u8def\u5f84\u957f\u5ea6\u4e3a 0 \u65f6\uff0c\u8003\u8651\u5230\u8fd9\u4e24\u9898\u5728\u4e00\u4e2d\u7684\u65f6\u4faf\u90fd\u7ed9\u9ad8\u4e00\u7684\u65b0\u751f\u4eec\u8bb2\u8fc7\u8bfe\uff0c\u6240\u4ee5\u53ef\u4ee5\u76f4\u63a5\u770b\u5230\uff0c1A\uff09<br \/>\n\u5269\u4e0b\u7684\u65f6\u95f4\u6162\u6162\u78d5\u7b2c\u4e09\u9898\uff0c\u51c6\u5907\u7684\u4e5f\u6bd4\u8f83\u5145\u5206\uff0c\u5728\u6bd4\u8d5b\u7ed3\u675f15\u5206\u949f\u524d 1A &#8230;<\/p>\n<p><bk><br \/>\n<bk><\/p>\n<h3>Archieve :<\/h3>\n<p>\u8d34\u4ee3\u7801:\u3002\u3002\u3002 patch() \u90e8\u5206\u662f\u8c03\u8bd5\u7684\u65f6\u4faf\u7528\u7684\u3002\u3002\u8981\u4fdd\u7559\u6bd4\u8d5b\u7684\u6c14\u6c1b\u3002\u3002<\/p>\n<pre lang=\"cpp\" file=\"A.cpp\">\r\n#include <iostream>\r\nusing namespace std;\r\nconst int N = 120+2;\r\nconst int dir[4][2] = {{1, 0}, {-1, 0}, {0, -1}, {0 , 1}};\r\nchar a[N][N], b[N][N];\r\nint n, m, ans;\r\n\r\n\r\nint r(int i){\r\n    if (i==0) return 1;\r\n    if (i==1) return 0;\r\n    if (i==2) return 3;\r\n    if (i==3) return 2;\r\n}\r\n\r\nvoid patch(){\r\n    for (int i=0;i<n+2;i++){\r\n        for (int j=0;j<n+2;j++)\r\n            cout << a[i][j];\r\n        cout << endl;\r\n    }\r\n}\r\n\r\nvoid dfs(int x, int y, int l, int s){\r\n    a[x][y] = 'o'; \/\/ patch(); cin >> m;\r\n\r\n    int xx, yy, xxx, yyy, bonus;\r\n    for (int i=0;i<4;i++){\r\n        if (i==l) continue;\r\n        xx = x + dir[i][0]; yy = y + dir[i][1];\r\n        if (a[xx][yy]!='.') continue;\r\n        bonus = 1; xxx = xx + dir[i][0]; yyy = yy + dir[i][1];\r\n        while (a[xxx][yyy]=='.'){\r\n            a[xx][yy] = 'o'; bonus++;\r\n            xx = xxx; yy = yyy; xxx += dir[i][0]; yyy += dir[i][1];\r\n        }\r\n\r\n        ans = max(ans, s + bonus);\r\n        if (a[xxx][yyy]=='#')\r\n            dfs(xx, yy, r(i), s + bonus);\r\n\r\n        while (xx!=x||yy!=y) {\r\n            a[xx][yy]='.';\r\n            xx -= dir[i][0]; yy -= dir[i][1];\r\n        }\r\n\/\/cout << \"dir:\" << i << endl;\r\n       \/\/ patch(); cin >> m;\r\n    }\r\n\r\n    a[x][y] = '.';\r\n}\r\n\r\nvoid init(){\r\n    int x, y; char z;\r\n    memset(a, '.', sizeof(a));\r\n    for (int i=0;i<m;i++){\r\n        scanf(\" %c%d\", &#038;z, &#038;x);\r\n        y = int(z-'A')+1; a[x][y] = '#';\r\n    }\r\n    for (int i=1;i<=n;i++)\r\n        a[i][0] = a[i][n+1] = a[n+1][i] = a[0][i] = '#';\r\n    a[1][1] = 'o';\r\n}\r\n\r\n\r\n\r\nint main(){\r\n    while (cin >> n >> m){\r\n        init(); ans = 1; dfs(1, 1, -1, 1);\r\n        cout << ans << endl;\r\n    }\r\n}\r\n<\/pre>\n<pre lang=\"cpp\" file=\"B.cpp\">\r\n#include <iostream>\r\n#include <cstdio>\r\nusing namespace std;\r\nconst int F[9] = {1,1,2,6,24,120,720,5040,40320};\r\nint queue[40320], dist[40320], parient[40320]; char operation[40320];\r\nint hash[40320];\r\nint head, tail, goal;\r\nint a[8]; bool c[8];\r\n\r\n\r\nint cantor(){\r\n    int x = 0, t, i, j;\r\n    for (i=0;i<8;i++){\r\n        for (j=i+1,t=0;j<8;j++)\r\n            if (a[i]>a[j]) t++;\r\n        x = x * (8-i)  + t;\r\n    }\r\n    return x;\r\n}\r\n\r\nvoid recover(int x){\r\n    memset(c, false, sizeof(c));\r\n    memset(a, 0, sizeof(a));\r\n    int t, i;\r\n    for (i=0;i<8;i++){\r\n        while (c[a[i]]) a[i]++;\r\n        while (x >= F[7-i]){\r\n            x -= F[7-i]; a[i]++;\r\n            while (c[a[i]]) a[i]++;\r\n        }\r\n        c[a[i]++] = true;\r\n    }\r\n}\r\n\r\nvoid patch(){\r\n    for (int i=0;i<8;i++)\r\n        cout << a[i] << \" \";\r\n    cout << endl;\r\n}\r\n\r\n\r\nvoid enqueue(int code, char op){\r\n    if (hash[code][\/code]==-1){\r\n        queue[tail] = code; dist[tail] = dist[head] + 1; parient[tail] = head; operation[tail] = op;\r\n        hash[code][\/code] = tail++;\r\n    }\r\n}\r\n\r\nvoid operate_A(){\r\n    for (int i=0;i<4;i++) swap(a[i], a[7-i]); enqueue(cantor(), 'A');\r\n    for (int i=0;i<4;i++) swap(a[i], a[7-i]);\r\n}\r\n\r\nvoid operate_B(){\r\n    int t = a[0]; a[0] = a[3]; a[3] = a[2]; a[2] = a[1]; a[1] = t;\r\n    t = a[7]; a[7] = a[4]; a[4] = a[5]; a[5] = a[6]; a[6] = t; enqueue(cantor(), 'B');\r\n    t = a[0]; a[0] = a[1]; a[1] = a[2]; a[2] = a[3]; a[3] = t;\r\n    t = a[7]; a[7] = a[6]; a[6] = a[5]; a[5] = a[4]; a[4] = t;\r\n}\r\n\r\nvoid operate_C(){\r\n    int t = a[1]; a[1] = a[6]; a[6] = a[5]; a[5] = a[2]; a[2] = t; enqueue(cantor(), 'C');\r\n    t = a[1]; a[1] = a[2]; a[2] = a[5]; a[5] = a[6]; a[6] = t;\r\n}\r\n\r\n\r\nvoid bfs(){\r\n    dist[0] = 0; head = 0; tail = 1;\r\n    memset(hash, -1, sizeof(hash));\r\n    hash[queue[0]] = 0;\r\n\r\n    int p;\r\n    while (head<tail){\r\n        recover(queue[head]);\r\n        operate_A(); operate_B(); operate_C();\r\n        head ++;\r\n    }\r\n    \/\/cout << head << endl;\r\n}\r\n\r\n\r\n\r\nvoid print_path(int x){\r\n    if (parient[x]==0){\r\n        cout << operation[x];\r\n    }\r\n    else{\r\n        print_path(parient[x]);\r\n        cout << operation[x];\r\n    }\r\n}\r\n\r\n\r\nint main(){\r\n    for (int i=0;i<8;i++) a[i] = i+1;\r\n    queue[0] = cantor(); bfs();\r\n\r\n    while (scanf(\"%d\", &#038;a[0])==1){\r\n        for (int i=1;i<8;i++) scanf(\"%d\", &#038;a[i]);\r\n        int code = cantor();\r\n\r\n        if (code==0){\r\n            printf(\"0\\n\");\r\n            printf(\"\\n\");\r\n        }\r\n        else {\r\n            printf(\"%d\\n\", dist[hash[code][\/code]]);\r\n            print_path(hash[code][\/code]); printf(\"\\n\");\r\n        }\r\n    }\r\n}\r\n\r\n<\/pre>\n<pre lang=\"cpp\" file=\"C.cpp\">\r\n#include <iostream>\r\nusing namespace std;\r\n\r\nint n, m, s;\r\n\r\nvoid dfs(int z, int l, int r){\r\n   \/\/ cout << z << endl;\r\n    if (z!=m){\r\n        int p, q;\r\n        q = m&#038;~(z|l|r);\r\n        while (q!=0){\r\n            p = q&#038;-q; q-=p;\r\n            dfs(z+p, (l+p)<<1, (r+p)>>1);\r\n        }\r\n    }\r\n    else s++;\r\n}\r\n\r\nint main(){\r\n    while (cin >> n){\r\n        m = (1 << n) - 1; s = 0; dfs(0, 0, 0);\r\n        cout << s << endl;\r\n    }\r\n}\r\n<\/pre>\n<p><bk><br \/>\n<bk><br \/>\n<bk><\/p>\n<h3>External link :<\/h3>\n<p><a href=\"http:\/\/acm.hit.edu.cn\/judge\/contest_index.php\">HIT ACM 2010 Summer Contest 08 \u641c\u7d22\u7ec3\u4e60<\/a><br \/>\n<a href=\"http:\/\/www.matrix67.com\/blog\/archives\/122\">M67 \u4f4d\u8fd0\u7b97\u8bb2\u89e3\u7cfb\u5217\u6587\u7ae0\uff08\u76ee\u5f55\uff09<\/a><br \/>\n<a href=\"http:\/\/www.nocow.cn\/index.php\/Translate:USACO\/msquare\">IOI'96 Magic Squares \u9b54\u677f \u8bd1 by Felicia Crazy <\/a><\/p>\n<p>... PS \uff1a\u524d\u51e0\u5929\u7684\u65f6\u4faf xiaodai \u8bf4\u7ed3\u62dcOI\u5144\u5f1f\uff0c\uff5e \u6211\u89c9\u5f97\u524d\u7f00\u6362\u6210 ACM \u66f4\u597d\u4e00\u4e9b\u3002\u3002\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Background : \u5199\u603b\u7ed3\uff0c\u603b\u7684\u6765\u8bf4\u4eca\u5929\u9898\u76ee\u5199\u7684\u5f88\u6162\uff0c\u56e0\u4e3a\u8d5b\u524d\u77e5\u9053\u8003\u5bdf\u7684\u8303\u56f4\u662f\u641c\u7d22\uff0c\u6bd5\u7adf\u9664\u4e86\u4e00\u4e9b\u57fa\u672c\u7684\u641c\u7d22\u65b9\u6cd5\u8fd8\u662f\u77e5\u9053\u8fd9\u65b9\u9762\u4e0d\u662f\u5f88\u6709\u5fc3\u5f97\uff0c\u603b\u4e4b\u4eca\u5929\u7684\u6bd4\u8d5b\u6211\u7684\u65f6\u4faf\u76ee\u6807\uff0c\u662f \u201c\u6c42\u4e0d\u4e71\u201d\uff0c\u5728\u4ee3\u7801\u4e0d\u4e71\u7684\u57fa\u7840\u4e0a\u4e89\u53d6\u4e00\u6b21\u7f16\u7801\u901a\u8fc7\uff0c\u4e0d\u8fc7\u770b\u6765\u5440\u4eca\u5929\u7684\u7b56\u7565\u5f88\u6210\u529f\u7684\u5e2e\u52a9\u6211\u62ff\u5230\u4e86\u53c2\u52a0 Summer Contest\u96c6\u8bad\u961f \u7684\u7b2c\u4e00\u4e2aRank I\uff08\u6492\u4e2a\u82b1\u54e6 \\>. < \uff5e\uff09\u3002\u3002 \u5148\u5feb\u901f\u626b\u9898\uff0c\u53d1\u73b0 Problem B\uff0c\u548c Problem C \u90fd\u662f\u505a\u8fc7\u7684\uff0c\u800c\u4e14\u7b2c\u4e09\u9898N\u7687\u540e\u53ef\u4ee5\u5e94\u7528N\u7687\u540e\u95ee\u9898\u4f4d\u8fd0\u7b97\u65b9\u6cd5\u5feb\u901f\u7f16\u7801\u5b9e\u73b0\uff0c\u4e8e\u662f\u5148\u62c6\u8fd9\u9898\uff0c11min1A\u3002 \u4e4b\u540e\u8003\u8651\u5148\u5199 Problem A \u8fd8\u662f Problem B\uff0c\u56e0\u4e3a\u90a3\u65f6A\u9898\u6709\u51e0\u4e2a\u7591\u95ee\u7684\u5730\u65b9\uff0c\u51b3\u5b9a\u8fd8\u662f\u52a8\u624b\u5199B\u3002 ACM \u7684\u6bd4\u8d5b\u56e0\u4e3a\u6570\u636e\u4f1a\u591a\u7ec4\u4e00\u8d77\u51fa\u73b0\uff0c\u6240\u4ee5\u6362\u5199\u5468\u754c\u641c\u7d22\uff0c\u8fd8\u662f\u6bd4\u8f83\u6709\u628a\u63e1 1h.27min \u51fa\u89e3\u3002 \uff08\u6b64\u9898\u6709\u4e00\u4e2a\u53ef\u80fd\u9020\u6210 PE \u7684\u5730\u65b9\uff0c\u5c31\u662f\u5f53\u8def\u5f84\u957f\u5ea6\u4e3a 0 \u65f6\uff0c\u8003\u8651\u5230\u8fd9\u4e24\u9898\u5728\u4e00\u4e2d\u7684\u65f6\u4faf\u90fd\u7ed9\u9ad8\u4e00\u7684\u65b0\u751f\u4eec\u8bb2\u8fc7\u8bfe\uff0c\u6240\u4ee5\u53ef\u4ee5\u76f4\u63a5\u770b\u5230\uff0c1A\uff09 \u5269\u4e0b\u7684\u65f6\u95f4\u6162\u6162\u78d5\u7b2c\u4e09\u9898\uff0c\u51c6\u5907\u7684\u4e5f\u6bd4\u8f83\u5145\u5206\uff0c\u5728\u6bd4\u8d5b\u7ed3\u675f15\u5206\u949f\u524d 1A &#8230; Archieve : \u8d34\u4ee3\u7801:\u3002\u3002\u3002 patch() \u90e8\u5206\u662f\u8c03\u8bd5\u7684\u65f6\u4faf\u7528\u7684\u3002\u3002\u8981\u4fdd\u7559\u6bd4\u8d5b\u7684\u6c14\u6c1b\u3002\u3002 #include using namespace std; const int N = 120+2; const int dir[4][2] = {{1, 0}, [&hellip;]\n<\/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":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[1],"tags":[],"class_list":["post-136","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p2tdP7-2c","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/136","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=136"}],"version-history":[{"count":0,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/136\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/media?parent=136"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/categories?post=136"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/tags?post=136"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}