{"id":484,"date":"2020-04-09T11:02:47","date_gmt":"2020-04-09T03:02:47","guid":{"rendered":"http:\/\/ff.mhrooz.xyz\/?p=484"},"modified":"2020-04-09T16:16:42","modified_gmt":"2020-04-09T08:16:42","slug":"poj_3279_fliptile","status":"publish","type":"post","link":"https:\/\/blog.mhrooz.xyz\/index.php\/2020\/04\/09\/poj_3279_fliptile\/","title":{"rendered":"POJ 3279 Fliptile"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">\u9898\u610f<\/h2>\n\n\n\n<p>\u7ed9\u4f60\u4e00\u4e2a01\u77e9\u9635\uff0c\u77e9\u9635\u5927\u5c0f\u4e3aM x N\u3002\uff081 &lt;= M , N &lt;= 15\uff09<\/p>\n\n\n\n<p>\u6bcf\u6b21\u64cd\u4f5c\u9009\u62e9\u4e00\u4e2a\u683c\u5b50\uff0c\u4f7f\u5f97\u8be5\u683c\u5b50\u4e0e\u4e0a\u4e0b\u5de6\u53f3\u56db\u4e2a\u683c\u5b50\u7684\u503c\u7ffb\u8f6c\u3002 \u81f3\u5c11\u591a\u5c11\u6b21\u64cd\u4f5c\u53ef\u4ee5\u4f7f\u5f97\u77e9\u9635\u4e2d\u6240\u6709\u7684\u503c\u53d8\u4e3a0\uff1f<\/p>\n\n\n\n<p>\u8bf7\u8f93\u51fa\u7ffb\u8f6c\u65b9\u6848\uff0c\u82e5\u6ca1\u6709\u65b9\u6848\uff0c\u8f93\u51fa&#8221;IMPOSSIBLE\u201d\u3002<\/p>\n\n\n\n<p> \u82e5\u6709\u591a\u79cd\u65b9\u6848\u7b26\u5408\u9898\u610f\uff0c\u8bf7\u9996\u5148\u8f93\u51fa\u7ffb\u8f6c\u6b21\u6570\u6700\u5c11\u7684\u65b9\u6848\uff1b\u82e5\u65b9\u6848\u4e2a\u6570\u4ecd\u4e0d\u552f\u4e00\uff0c\u5219\u8f93\u51fa\u5b57\u5178\u5e8f\u6700\u5c0f\u7684\u65b9\u6848\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u9898\u89e3<\/h3>\n\n\n\n<p>\u679a\u4e3e\u7b2c\u4e00\u884c\u7684\u6240\u6709\u60c5\u51b5<\/p>\n\n\n\n<p>\u4ece\u7b2c\u4e8c\u884c\u5f00\u59cb\u5230\u6700\u540e\u4e00\u884c\uff0c\u5982\u679c\u5f53\u524d\u683c\u5b50\u7684\u4e0a\u4e00\u4e2a\u884c\u5bf9\u5e94\u7684\u683c\u5b50\u4e3a1\uff0c\u8868\u793a\u5c31\u8981\u53cd\u8f6c\u5f53\u524d\u7684\u683c\u5b50<\/p>\n\n\n\n<p>\u6700\u540e\u68c0\u9a8c\u6700\u540e\u4e00\u884c\u662f\u5426\u5168\u4e3a0<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u4ee3\u7801<\/h3>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"true\" data-enlighter-lineoffset=\"0\" data-enlighter-title=\"\" data-enlighter-group=\"\">#include &lt;algorithm>\n#include &lt;climits>\n#include &lt;cmath>\n#include &lt;cstdio>\n#include &lt;cstdlib>\n#include &lt;cstring>\n#include &lt;iostream>\n#include &lt;map>\n#include &lt;queue>\n#include &lt;set>\n#include &lt;stack>\n#include &lt;string>\n#include &lt;vector>\n\nusing namespace std;\ntypedef long long ll;\nint mp[30][30], tmp[30][30];\nint n, m;\nint dx[5] = {0, 0, 0, 0, -1};\nint dy[5] = {0, 0, -1, 1, 0};\/\/\u56db\u4e2a\u65b9\u5411\u5206\u522b\u662f\u81ea\u5df1\uff0c\u4e0a\uff0c\u5de6\uff0c\u53f3\nint pr[30][30];\/\/\u7b54\u6848\u6570\u7ec4\nint work()\n{\n    for (int i = 1; i &lt; n; i++)\n    {\n        for (int j = 1; j &lt;= m; j++)\n        {\n            int t = mp[i][j], cnt = 0;\/\/t\u8868\u793a\u5f53\u524d\u5757\u662f1\u8fd8\u662f0\n            for (int k = 1; k &lt;= 4; k++)\/\/\u524d\u4e00\u884c\u7684\u56db\u4e2a\u65b9\u5411\n            {\n                int x = i + dx[k];\n                int y = j + dy[k];\n                t += tmp[x][y];\/\/\u5982\u679c\u672c\u8eab\u662f1\uff0c\u5947\u6570\u6b21\u53cd\u8f6c\u8fd8\u662f0\uff0c\u5076\u6570\u6b21\u53cd\u8f6c\u662f1\uff0c\u672c\u8eab\u662f0\u53cd\u4e4b\n            }\n            if (t &amp; 1)\/\/\u5982\u679c\u5f53\u524d\u5757\u662f1\n                tmp[i+1][j] = 1;\/\/\u4e0b\u4e00\u884c\u5bf9\u5e94\u7684\u5757\u6362\u4e3a1\u4fdd\u8bc1\u5f53\u524d\u4e3a0\n        }\n    }\n    \/\/\u68c0\u9a8c\u6700\u540e\u4e00\u884c\u662f\u5426\u4e3a0\n    int i = n;\n    for (int j = 1; j &lt;= m; j++)\n    {\n        int t = mp[i][j], cnt = 0;\n        for (int k = 1; k &lt;= 4; k++)\n        {\n            int x = i + dx[k];\n            int y = j + dy[k];\n            t += tmp[x][y];\n        }\n        if (t &amp; 1)\/\/\u4e0d\u5408\u683c\u5c31\u63a8\u51fa\n            return -1;\n    }\n    int ans = 0;\n    for (int i = 1; i &lt;= n; i++)\n        for (int j = 1; j &lt;= m; j++)\n            if (tmp[i][j] &amp; 1)\n                ans++;\n    return ans;\n}\nint main()\n{\n    \/\/ freopen(\"a.in\",\"r\",stdin);\n    cin >> n >> m;\n    for (int i = 1; i &lt;= n; i++)\n        for (int j = 1; j &lt;= m; j++)\n            cin >> mp[i][j];\n    int ans = 0x3f3f3f3f;\n    for (int i = 0; i &lt; (1 &lt;&lt; n); i++)\n    {\n        memset(tmp,0,sizeof(tmp));\n        for (int j = 0; j &lt; m; j++)\n            tmp[1][j+1] = (i >> j) &amp; 1;\/\/\u679a\u4e3e\u7b2c\u4e00\u884c\u7684\u6240\u6709\u60c5\u51b5\n        int t = work();\n        if (t == -1)\n            continue;\n        if (ans > t){\n            ans =t;\n            for (int i = 1; i &lt;= n; i++)\n                for (int j = 1; j &lt;= m; j++)\n                    pr[i][j] = tmp[i][j];\n        }\n    }\n    if(ans==0x3f3f3f3f)\n        return cout&lt;&lt;\"IMPOSSIBLE\"&lt;&lt;endl,0;\n    for (int i = 1; i &lt;= n; i++)\n    {\n        for (int j = 1; j &lt;= m; j++)\n            cout &lt;&lt; pr[i][j] &lt;&lt; ' ';\n        cout &lt;&lt; endl;\n    }\n    return 0;\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u9898\u610f \u7ed9\u4f60\u4e00\u4e2a01\u77e9\u9635\uff0c\u77e9\u9635\u5927\u5c0f\u4e3aM x N\u3002\uff081 &lt;= M , N &lt;= 15\uff09 \u6bcf\u6b21\u64cd\u4f5c\u9009\u62e9\u4e00<a class=\"more-link\" href=\"https:\/\/blog.mhrooz.xyz\/index.php\/2020\/04\/09\/poj_3279_fliptile\/\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">&#8220;POJ 3279 Fliptile&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/blog.mhrooz.xyz\/index.php\/wp-json\/wp\/v2\/posts\/484"}],"collection":[{"href":"https:\/\/blog.mhrooz.xyz\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.mhrooz.xyz\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.mhrooz.xyz\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.mhrooz.xyz\/index.php\/wp-json\/wp\/v2\/comments?post=484"}],"version-history":[{"count":5,"href":"https:\/\/blog.mhrooz.xyz\/index.php\/wp-json\/wp\/v2\/posts\/484\/revisions"}],"predecessor-version":[{"id":493,"href":"https:\/\/blog.mhrooz.xyz\/index.php\/wp-json\/wp\/v2\/posts\/484\/revisions\/493"}],"wp:attachment":[{"href":"https:\/\/blog.mhrooz.xyz\/index.php\/wp-json\/wp\/v2\/media?parent=484"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.mhrooz.xyz\/index.php\/wp-json\/wp\/v2\/categories?post=484"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.mhrooz.xyz\/index.php\/wp-json\/wp\/v2\/tags?post=484"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}