{"id":138,"date":"2023-04-20T19:49:43","date_gmt":"2023-04-20T11:49:43","guid":{"rendered":"https:\/\/solost.cn\/?p=138"},"modified":"2023-04-20T19:49:43","modified_gmt":"2023-04-20T11:49:43","slug":"246","status":"publish","type":"post","link":"https:\/\/solost.cn\/?p=138","title":{"rendered":"Codeforces Round 712 (Div. 1) &#8211; B. 3-Coloring"},"content":{"rendered":"<h2>\u9898\u76ee<\/h2>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2026\/11\/image-23.png\" alt=\"image.png\" title=\"image.png\"><\/p>\n<h2>\u9898\u76ee\u94fe\u63a5<\/h2>\n<p><a href=\"https:\/\/codeforces.com\/contest\/1503\/problem\/B\">\u94fe\u63a5<\/a><\/p>\n<h2>\u9898\u76ee\u5927\u610f<\/h2>\n<p>\u9898\u76ee\u610f\u601d\u662f\u7ed9\u4f60\u4e00\u4e2a\u4f60n * n\u7684\u68cb\u76d8\uff0c\u4f60\u6709\u4e09\u79cd\u68cb\u5b50\uff0c\u6bcf\u6b21\u7ed9\u4f60\u4e00\u79cd\u68cb\u5b50\uff0c\u4f60\u4e0d\u80fd\u653e\u8fd9\u79cd\u68cb\u5b50\u8fd9\u6b21\uff0c\u653e\u7684\u68cb\u5b50\u76f8\u90bb\u4e0d\u76f8\u540c\uff0c\u95ee\u4f60\u600e\u4e48\u653e\uff0c\u6bcf\u6b21\u8f93\u51fa\u653e\u7684\u68cb\u5b50\u79cd\u7c7b\u548c\u4f4d\u7f6e<\/p>\n<h2>\u9898\u89e3<\/h2>\n<p>\u521a\u5f00\u59cb\u7684\u60f3\u6cd5\u662f\u76f4\u63a5\u66b4\u529b\u627e\uff0c\u7136\u540e\u8d85\u65f6\uff0c\u7136\u540e\u7528vector\u5b58\u8d77\u6765\u6bcf\u6b21\u6ca1\u6709\u4f7f\u7528\u8fc7\u7684\u4f4d\u7f6e\uff0c\u5728\u5224\u65ad\u76f8\u90bb\u7684\u6709\u6ca1\u6709\u76f8\u540c\u7684\u68cb\u5b50\uff0c\u7136\u540e\u8d85\u7a7a\u95f4\u3002\u6700\u540e\u770b\u4e86\u522b\u4eba\u7684\u9898\u89e3\u3002\u601d\u8def\u662f\u628a\u95f4\u9694\u7684\u683c\u5b50\u4f4d\u7f6e\u5206\u522b\u5b58\u8d77\u6765\u300b\u4e5f\u5c31\u662f<code>i + j &amp; 1<\/code>\u8fd9\u5c31\u662f\u95f4\u9694\u7684\u683c\u5b50\uff0c\u5c31\u8ddf\u56fd\u9645\u8c61\u68cb\u4e00\u6837\u7684\u683c\u5b50\u3002\u5047\u8bbe\u767d\u7684\u683c\u5b50\u662fa,\u9ed1\u7684\u662fb,\u7ed9\u4f60\u4e00\u4e2a\u68cb\u5b50\uff0c\u5982\u679c\u662f\u672c\u6b21\u4e0d\u8ba9\u653e1\u68cb\u5b50\uff0c\u6211\u4eec\u5c31\u5f80b\u653e2\u68cb\u5b50\uff0c\u53cd\u4e4b\u5f80a\u653e1\u68cb\u5b50\uff0c\u5982\u679c\u6709\u4e00\u79cd\u683c\u5b50\u653e\u5b8c\u4e86\uff0c\u4f8b\u5982\u8bf4\u767d\u8272\u683c\u5b50\u7528\u5b8c\u4e86\uff0c\u90a3\u6211\u4eec\u5c31\u5f80\u9ed1\u8272\u683c\u5b50\u653e2\uff0c3\u3002\u9ed1\u8272\u683c\u5b50\u7528\u5b8c\u4e86\u5c31\u653e1\uff0c3\uff0c\u7136\u540e\u5c31\u53ef\u4ee5\u8fbe\u5230\u76f8\u90bb\u4e0d\u76f8\u540c\u7684\u76ee\u7684\u3002\u56e0\u4e3a\u603b\u6709\u4e00\u79cd\u683c\u5b50\u5168\u90e8\u662f1\u6216\u8005\u5168\u90e8\u662f2\uff0c\u5269\u4e0b\u6ca1\u7528\u5b8c\u7684\u5c31\u662f2\uff0c3\uff0c\u6216\u80051\uff0c3\uff0c\u6240\u4ee5\u53ef\u4ee5\u8fbe\u5230\u76ee\u7684\u3002<\/p>\n<p>\u4e0a\u4ee3\u7801\uff1a<\/p>\n<pre><code class=\"lang-cpp\">#include &lt;algorithm&gt;\n#include &lt;bitset&gt;\n#include &lt;cmath&gt;\n#include &lt;cstdio&gt;\n#include &lt;cstdlib&gt;\n#include &lt;cstring&gt;\n#include &lt;fstream&gt;\n#include &lt;iostream&gt;\n#include &lt;map&gt;\n#include &lt;queue&gt;\n#include &lt;set&gt;\n#include &lt;stack&gt;\n#include &lt;unordered_map&gt;\n#include &lt;unordered_set&gt;\n#include &lt;vector&gt;\n\n#define x first\n#define y second\n#define endl &#039;\\n&#039;\n#define IOS                       \\\n    ios_base::sync_with_stdio(0); \\\n    cin.tie(0);                   \\\n    cout.tie(0);\n\nusing namespace std;\n\ntypedef long long ll;\ntypedef pair&lt;ll, ll&gt; pll;\ntypedef pair&lt;int, int&gt; pii;\ntypedef unsigned long long ull;\n\nconst int INF = 0x3f3f3f3f, mod = 1000000007;\nconst int N = 110;\n\npii a[N * N], b[N * N];\n\nvoid solve()\n{\n    int n;\n    cin &gt;&gt; n;\n    int l1 = 0, l2 = 0;\n    for (int i = 1; i &lt;= n; i++) {\n        for (int j = 1; j &lt;= n; j++) {\n            if (i + j &amp; 1) {\n                a[++l1] = { i, j };\n            } else {\n                b[++l2] = { i, j };\n            }\n        }\n    }\n    int x;\n    for (int i = 1; i &lt;= n * n; i++) {\n        cin &gt;&gt; x;\n        if(!l1){\n            cout &lt;&lt; (x == 2 ? 3 : 2) &lt;&lt; &quot; &quot; &lt;&lt; b[l2].x &lt;&lt; &quot; &quot; &lt;&lt; b[l2].y &lt;&lt; endl;\n            l2--;\n            continue;\n        }\n        if(!l2){\n            cout &lt;&lt; (x == 1 ? 3 : 1) &lt;&lt; &quot; &quot; &lt;&lt; a[l1].x &lt;&lt; &quot; &quot; &lt;&lt; a[l1].y &lt;&lt; endl;\n            l1--;\n            continue;\n        }\n        if(x == 1){\n            cout &lt;&lt; 2 &lt;&lt; &quot; &quot; &lt;&lt; b[l2].x &lt;&lt; &quot; &quot; &lt;&lt; b[l2].y &lt;&lt; endl;\n            l2--;\n        }\n        else{\n            cout &lt;&lt; 1 &lt;&lt; &quot; &quot; &lt;&lt; a[l1].x &lt;&lt; &quot; &quot; &lt;&lt; a[l1].y &lt;&lt; endl;\n            l1--;\n        }\n    }\n}\nint main()\n{\n    \/\/ IOS;\n    int t = 1;\n    \/\/ cin &gt;&gt; t;\n    while (t--) {\n        solve();\n    }\n    return 0;\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u9898\u76ee \u9898\u76ee\u94fe\u63a5 \u94fe\u63a5 \u9898\u76ee\u5927\u610f \u9898\u76ee\u610f\u601d\u662f\u7ed9\u4f60\u4e00\u4e2a\u4f60n * n\u7684\u68cb\u76d8\uff0c\u4f60\u6709\u4e09\u79cd\u68cb\u5b50\uff0c\u6bcf\u6b21\u7ed9\u4f60\u4e00\u79cd\u68cb\u5b50\uff0c\u4f60\u4e0d\u80fd\u653e\u8fd9\u79cd\u68cb\u5b50\u8fd9\u6b21\uff0c\u653e\u7684\u68cb\u5b50\u76f8\u90bb\u4e0d\u76f8\u540c\uff0c\u95ee\u4f60\u600e\u4e48\u653e\uff0c\u6bcf\u6b21\u8f93\u51fa\u653e\u7684\u68cb\u5b50\u79cd\u7c7b\u548c\u4f4d\u7f6e \u9898\u89e3 \u521a\u5f00\u59cb\u7684\u60f3\u6cd5\u662f\u76f4\u63a5\u66b4\u529b\u627e\uff0c\u7136\u540e\u8d85\u65f6\uff0c\u7136\u540e\u7528vector\u5b58\u8d77\u6765\u6bcf\u6b21\u6ca1\u6709\u4f7f\u7528\u8fc7\u7684\u4f4d\u7f6e\uff0c\u5728\u5224\u65ad\u76f8\u90bb\u7684\u6709\u6ca1\u6709\u76f8\u540c\u7684\u68cb\u5b50\uff0c\u7136\u540e\u8d85\u7a7a\u95f4\u3002\u6700\u540e\u770b\u4e86\u522b\u4eba\u7684\u9898\u89e3\u3002\u601d\u8def\u662f\u628a\u95f4\u9694\u7684\u683c\u5b50\u4f4d\u7f6e\u5206\u522b\u5b58\u8d77\u6765\u300b\u4e5f\u5c31\u662fi + j &amp; 1\u8fd9\u5c31\u662f\u95f4\u9694\u7684\u683c\u5b50\uff0c\u5c31\u8ddf\u56fd\u9645\u8c61\u68cb\u4e00\u6837\u7684\u683c\u5b50\u3002\u5047\u8bbe\u767d\u7684\u683c\u5b50\u662fa,\u9ed1\u7684\u662fb,\u7ed9\u4f60\u4e00\u4e2a\u68cb\u5b50\uff0c\u5982\u679c\u662f\u672c\u6b21\u4e0d\u8ba9\u653e1\u68cb\u5b50\uff0c\u6211\u4eec\u5c31\u5f80b\u653e2\u68cb\u5b50\uff0c\u53cd\u4e4b\u5f80a\u653e1\u68cb\u5b50\uff0c\u5982\u679c\u6709\u4e00\u79cd\u683c\u5b50\u653e\u5b8c\u4e86\uff0c\u4f8b\u5982\u8bf4\u767d\u8272\u683c\u5b50\u7528\u5b8c\u4e86\uff0c\u90a3\u6211\u4eec\u5c31\u5f80\u9ed1\u8272\u683c\u5b50\u653e2\uff0c3\u3002\u9ed1\u8272\u683c\u5b50\u7528\u5b8c\u4e86\u5c31\u653e1\uff0c3\uff0c\u7136\u540e\u5c31\u53ef\u4ee5\u8fbe\u5230\u76f8\u90bb\u4e0d\u76f8\u540c\u7684\u76ee\u7684\u3002\u56e0\u4e3a\u603b\u6709\u4e00\u79cd\u683c\u5b50\u5168\u90e8\u662f1\u6216\u8005\u5168\u90e8\u662f2\uff0c\u5269\u4e0b\u6ca1\u7528\u5b8c\u7684\u5c31\u662f2\uff0c3\uff0c\u6216\u80051\uff0c3\uff0c\u6240\u4ee5\u53ef\u4ee5\u8fbe\u5230\u76ee\u7684\u3002 \u4e0a\u4ee3\u7801\uff1a #include &lt;algorithm&gt; #include &lt;bitset&gt; #include &lt;cmath&gt; #include &lt;cstdio&gt; #include &lt;cstdlib&gt; #include &lt;cstring&gt; #include &lt;fstream&gt; #include &lt;iostream&gt; #include &lt;map&gt; #include &lt;queue&gt; #include &lt;set&gt; #include &lt;stack&gt; #include &lt;unordered_map&gt; #include &lt;unordered_set&gt; #include &lt;vector&gt; #define x first #define y second #define endl &#039;\\n&#039; #define IOS [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[54,5],"class_list":["post-138","post","type-post","status-publish","format-standard","hentry","category-solution","tag-interactive","tag-5"],"_links":{"self":[{"href":"https:\/\/solost.cn\/index.php?rest_route=\/wp\/v2\/posts\/138","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/solost.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/solost.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/solost.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/solost.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=138"}],"version-history":[{"count":0,"href":"https:\/\/solost.cn\/index.php?rest_route=\/wp\/v2\/posts\/138\/revisions"}],"wp:attachment":[{"href":"https:\/\/solost.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=138"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/solost.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=138"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/solost.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=138"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}