{"id":29,"date":"2023-01-24T21:26:00","date_gmt":"2023-01-24T13:26:00","guid":{"rendered":"https:\/\/solost.cn\/?p=29"},"modified":"2023-02-02T00:51:59","modified_gmt":"2023-02-01T16:51:59","slug":"63","status":"publish","type":"post","link":"https:\/\/solost.cn\/?p=29","title":{"rendered":"1250. \u683c\u5b50\u6e38\u620f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2026\/11\/1909121154.png\" alt=\"\" title=\"\"><\/p>\n<h2>\u9898\u76ee\u5927\u610f<\/h2>\n<p>\u9898\u76ee\u5927\u6982\u610f\u601d\u662f\u6bcf\u6b21\u53ef\u4ee5\u4ecex, y\u5230x+1,y\u6216\u8005x,y+1,\u5982\u679c\u51fa\u73b0\u73af\u5c31\u8f93\u51fa\u7b2c\u51e0\u56de\u5408\u51fa\u73b0\u73af\u7684\uff0c\u5426\u5219\u5c31\u8f93\u51fadraw\u3002<\/p>\n<h2>solution<\/h2>\n<p>\u8fd9\u9053\u9898\u5c31\u662f\u5224\u65ad\u51fa\u73b0\u73af\u7684\u95ee\u9898\uff0c\u6211\u4eec\u5047\u8bbe\uff0c\u5f53\u524d\u70b9\u662fx,y\uff0c\u4e0b\u4e00\u4e2a\u8fde\u63a5\u7684\u70b9,\u5982\u679c\u4e24\u4e2a\u70b9\u7684\u7236\u4eb2\u4e00\u6837\uff0c\u90a3\u4e48\u5c31\u53ef\u4ee5\u786e\u5b9a\u73b0\u5728\u5df2\u7ecf\u51fa\u73b0\u4e86\u73af\u3002<\/p>\n<h3>\u5e76\u67e5\u96c6\u5199\u6cd5<\/h3>\n<pre><code class=\"lang-cpp\">int find(int x)\n{\n    if(x != p[x]) p[x] = find(p[x);\n    return p[x];\n}\n<\/code><\/pre>\n<h3>\u4e8c\u7ef4\u6570\u7ec4\u538b\u7f29\u4e3a\u4e00\u7ef4<\/h3>\n<p>\u7531\u4e8e\u5e76\u67e5\u96c6\u67e5\u627e\u7236\u4eb2\u662f\u4e00\u4e2a\u4e00\u4f4d\u5750\u6807\uff0c\u9700\u8981\u628a\u4e8c\u7ef4\u6570\u7ec4\u538b\u7f29\u6210\u4e3a\u4e00\u4e2a\u7ef4\u5ea6\u6765\u8868\u793a\u4ed6\u7684\u7236\u4eb2\u3002<\/p>\n<p>\u5f53\u5750\u6807\u4ece(0,0)\u5f00\u59cb\u7684\u65f6\u5019\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06d = x * n + y,n\u5c31\u662f\u884c\u6570\uff0c\u6240\u4ee5\u6211\u4eec\u5c31\u53ef\u4ee5\u8fd9\u6837\u6765\u8868\u793a\u3002<\/p>\n<pre><code class=\"lang-CPP\">#include &lt;bits\/stdc++.h&gt;\n\nusing namespace std;\nint n, m;\nconst int N = 4010; \/\u4e8c\u7ef4\u538b\u7f29\u8fc7\u6765\u6700\u591a\u7684\u70b9\u7684\u4e2a\u6570\nint p[N];\nint find(int x){\n    if(p[x] != x) p[x] = find(p[x]);\n    return p[x];\n}\nint get(int x, int y){\n    return x * n + y;\n}\nint main(){\n    cin &gt;&gt; n &gt;&gt; m;\n    for(int i = 0; i &lt;= n * n; i++) p[i] = i;\n    int res = 0;\n    for(int i = 1; i &lt;= m; i++){\n        int x, y, a, b;\n        char op;\n        cin &gt;&gt; x &gt;&gt; y &gt;&gt; op;\n        x--, y--;\n        a = get(x, y);\n        if(op == &#039;D&#039;) b = get(x + 1, y);\n        else b = get(x, y + 1);\n        int fa = find(a);\n        int fb = find(b);\n        if(fa != fb) p[fb] = fa;\n        else{\n            res = i;\n            break;\n        }\n    }\n    if(!res) puts(&quot;draw&quot;);\n    else cout &lt;&lt; res &lt;&lt; endl;\n    return 0;\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u9898\u76ee\u5927\u610f \u9898\u76ee\u5927\u6982\u610f\u601d\u662f\u6bcf\u6b21\u53ef\u4ee5\u4ecex, y\u5230x+1,y\u6216\u8005x,y+1,\u5982\u679c\u51fa\u73b0\u73af\u5c31\u8f93\u51fa\u7b2c\u51e0\u56de\u5408\u51fa\u73b0\u73af\u7684\uff0c\u5426\u5219\u5c31\u8f93\u51fadraw\u3002 solution \u8fd9\u9053\u9898\u5c31\u662f\u5224\u65ad\u51fa\u73b0\u73af\u7684\u95ee\u9898\uff0c\u6211\u4eec\u5047\u8bbe\uff0c\u5f53\u524d\u70b9\u662fx,y\uff0c\u4e0b\u4e00\u4e2a\u8fde\u63a5\u7684\u70b9,\u5982\u679c\u4e24\u4e2a\u70b9\u7684\u7236\u4eb2\u4e00\u6837\uff0c\u90a3\u4e48\u5c31\u53ef\u4ee5\u786e\u5b9a\u73b0\u5728\u5df2\u7ecf\u51fa\u73b0\u4e86\u73af\u3002 \u5e76\u67e5\u96c6\u5199\u6cd5 int find(int x) { if(x != p[x]) p[x] = find(p[x); return p[x]; } \u4e8c\u7ef4\u6570\u7ec4\u538b\u7f29\u4e3a\u4e00\u7ef4 \u7531\u4e8e\u5e76\u67e5\u96c6\u67e5\u627e\u7236\u4eb2\u662f\u4e00\u4e2a\u4e00\u4f4d\u5750\u6807\uff0c\u9700\u8981\u628a\u4e8c\u7ef4\u6570\u7ec4\u538b\u7f29\u6210\u4e3a\u4e00\u4e2a\u7ef4\u5ea6\u6765\u8868\u793a\u4ed6\u7684\u7236\u4eb2\u3002 \u5f53\u5750\u6807\u4ece(0,0)\u5f00\u59cb\u7684\u65f6\u5019\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06d = x * n + y,n\u5c31\u662f\u884c\u6570\uff0c\u6240\u4ee5\u6211\u4eec\u5c31\u53ef\u4ee5\u8fd9\u6837\u6765\u8868\u793a\u3002 #include &lt;bits\/stdc++.h&gt; using namespace std; int n, m; const int N = 4010; \/\u4e8c\u7ef4\u538b\u7f29\u8fc7\u6765\u6700\u591a\u7684\u70b9\u7684\u4e2a\u6570 int p[N]; int find(int x){ if(p[x] != x) p[x] = find(p[x]); return p[x]; [&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":[13,12],"class_list":["post-29","post","type-post","status-publish","format-standard","hentry","category-solution","tag-13","tag-12"],"_links":{"self":[{"href":"https:\/\/solost.cn\/index.php?rest_route=\/wp\/v2\/posts\/29","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=29"}],"version-history":[{"count":0,"href":"https:\/\/solost.cn\/index.php?rest_route=\/wp\/v2\/posts\/29\/revisions"}],"wp:attachment":[{"href":"https:\/\/solost.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=29"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/solost.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=29"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/solost.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=29"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}