{"id":33,"date":"2019-03-11T14:38:01","date_gmt":"2019-03-11T06:38:01","guid":{"rendered":"http:\/\/www.guanhaobo.cn\/?p=33"},"modified":"2019-03-11T14:38:01","modified_gmt":"2019-03-11T06:38:01","slug":"poj-1013-counterfeit-dollar","status":"publish","type":"post","link":"https:\/\/www.guanhaobo.cn\/?p=33","title":{"rendered":"POJ 1013 \u2014 Counterfeit Dollar"},"content":{"rendered":"<h4>\u9898\u76ee\u5927\u610f<\/h4>\n<p>12\u679a\u786c\u5e01\u4e2d\u53ea\u67091\u679a\u5047\u5e01\uff0c\u5047\u5e01\u6bd4\u771f\u5e01\u8f7b\u6216\u8005\u6bd4\u771f\u5e01\u91cd\u3002\u7528\u5929\u5e73\u79f0\u4e86\u786c\u5e01\u4e09\u6b21\uff0c\u6bcf\u6b21\u5929\u5e73\u5de6\u8fb9\u7684\u786c\u5e01\u6570\u90fd\u548c\u53f3\u8fb9\u7684\u786c\u5e01\u6570\u76f8\u7b49\u3002\u95ee\u54ea\u4e00\u679a\u786c\u5e01\u662f\u5047\u5e01\u5e76\u4e14\u786e\u5b9a\u5047\u5e01\u662f\u8f7b\u662f\u91cd\u3002<\/p>\n<p><!--more--><\/p>\n<h4>\u9898\u76ee\u94fe\u63a5<\/h4>\n<p><a href=\"http:\/\/poj.org\/problem?id=1013\" title=\"http:\/\/poj.org\/problem?id=1013\">http:\/\/poj.org\/problem?id=1013<\/a><\/p>\n<h4>\u8f93\u5165<\/h4>\n<p>\u7b2c\u4e00\u884c\u662f\u6d4b\u8bd5\u6570\u636e\u7ec4\u6570n\u3002\u6bcf\u7ec4\u6570\u636e\u6709\u4e09\u884c\uff0c\u5206\u522b\u8868\u793a\u4e09\u6b21\u79f0\u91cf\u7684\u7ed3\u679c\u3002\u786c\u5e01\u5206\u522b\u7528A-L\u8868\u793a\u3002\u6bcf\u6b21\u79f0\u91cf\u7684\u7ed3\u679c\u7528\u4e09\u4e2a\u5b57\u7b26\u4e32\u8868\u793a\uff1a\u5929\u5e73\u5de6\u8fb9\u7684\u786c\u5e01 \u5929\u5e73\u53f3\u8fb9\u7684\u786c\u5e01 \u5929\u5e73\u72b6\u6001\u3002\u5929\u5e73\u72b6\u6001\u7528\u201dup\u201d, \u201cdown\u201d, \u201ceven\u201d\u5206\u522b\u8868\u793a\u53f3\u7aef\u9ad8\u3001\u53f3\u7aef\u4f4e\u548c\u5e73\u8861\u3002<\/p>\n<h4>\u8f93\u51fa<\/h4>\n<p>\u5bf9\u4e8e\u6bcf\u7ec4\u6570\u636e\uff0c\u8f93\u51fa\u4e00\u884c\uff0c\u5047\u5e01\u7684\u82f1\u6587\u7f16\u53f7\u4ee5\u53ca\u5047\u5e01\u7684\u8f7b\u91cd\u3002heavy\u8868\u793a\u5047\u5e01\u6bd4\u771f\u5e01\u91cd\uff0clight\u8868\u793a\u5047\u5e01\u6bd4\u771f\u5e01\u8f7b\u3002\u5177\u4f53\u53c2\u89c1\u6837\u4f8b\u8f93\u51fa\u3002<\/p>\n<h4>\u6837\u4f8b\u8f93\u5165<\/h4>\n<pre><code class=\"line-numbers\">1\nABCD EFGH even\nABCI EFJK up\nABIJ EFGH even\n<\/code><\/pre>\n<h4>\u6837\u4f8b\u8f93\u51fa<\/h4>\n<pre><code class=\"line-numbers\">K is the counterfeit coin and it is light.\n<\/code><\/pre>\n<h4>\u95ee\u9898\u5206\u6790<\/h4>\n<p>\u8fd9\u4e2a\u95ee\u9898\u7684\u601d\u8def\u5f88\u7b80\u5355\uff0c\u4f46\u5b9e\u73b0\u8d77\u6765\u5e76\u4e0d\u662f\u5f88\u5bb9\u6613\u3002\u786c\u5e01\u7684\u7f16\u53f7\u662fA-L\uff0c\u6240\u4ee5\u6211\u4eec\u53ea\u8981\u679a\u4e3e\u786c\u5e01A-L\uff0c\u5224\u65ad\u7f16\u53f7\u4e3aans\u7684\u786c\u5e01\u662f\u4e0d\u662f\u5047\u5e01\u5373\u53ef\u3002\u5b9e\u9645\u4e0a\uff0c\u5bf9\u4e8e\u4efb\u610f\u4e00\u4e2a\u786c\u5e01\uff0c\u5728\u4e09\u6b21\u79f0\u91cf\u4e2d\uff0c\u6709\u53ef\u80fd\u51fa\u73b00\u30011\u30012\u30013\u6b21\u3002\u56e0\u6b64\uff0c\u6211\u4eec\u9700\u8981\u6839\u636e\u5929\u5e73\u72b6\u6001\u6000\u7591\u786c\u5e01ans\u662f\u4e0d\u662f\u5047\u5e01\u4ee5\u53ca\u5b83\u7684\u8f7b\u91cd\uff0c\u6700\u540e\u5224\u65ad\u6240\u6709ans\u51fa\u73b0\u7684\u65f6\u5019\u5f97\u51fa\u7684\u7ed3\u8bba\u662f\u5426\u4e00\u81f4\u3002<\/p>\n<p>\u4f8b\u5982\uff0c\u5728\u6837\u4f8b\u4e2d\uff0c\u679a\u4e3e\u5230ans=\u2019K\u2019\u65f6\uff0cK\u53ea\u51fa\u73b0\u4e00\u6b21\uff0c\u6839\u636e\u7b2c\u4e8c\u6b21\u79f0\u91cf\u4f1a\u5f97\u5230K\u662f\u5047\u5e01\u7684\u7ed3\u8bba\u3002\u4f46\u8981\u6ce8\u610f\uff0c\u8fd9\u65f6\u4e0d\u80fd\u76f4\u63a5\u65ad\u5b9aK\u662f\u5047\u5e01\uff0c\u8fd8\u9700\u8981\u4fdd\u8bc1\u6240\u6709K\u4e0d\u51fa\u73b0\u7684\u65f6\u5019\u5929\u5e73\u72b6\u6001\u4e3a\u201deven\u201d\uff0c\u5373\u5269\u4f59\u4e24\u6b21\u79f0\u91cf\u5929\u5e73\u5747\u4e3a\u201deven\u201d\uff0c\u8fd9\u4e00\u70b9\u5f88\u91cd\u8981\u3002\u53ea\u51fa\u73b0\u4e24\u6b21\u7684\u4e5f\u8981\u8fdb\u884c\u7c7b\u4f3c\u5224\u65ad\u3002<\/p>\n<h4>AC\u4ee3\u7801<\/h4>\n<pre><code class=\"language-cpp line-numbers\">#include &lt;iostream&gt;\n#include &lt;string&gt;\nusing namespace std;\nstring s1[3], s2[3], s3[3];\n\nint f(char ans, int i) \/\/\u8fd4\u56de\u503c\u4e3a1\u4ee3\u8868\u91cd\uff0c0\u4ee3\u8868\u4e0d\u662f\u5047\u5e01\uff0c-1\u4ee3\u8868\u8f7b,-2\u8868\u793a\u6ca1\u627e\u5230\n{\n    int result = 0, t1 = 0, t2 = 0;\n    if (s1[i].rfind(ans) != -1)\n    {\n        if (s3[i] == \"up\")\n            result = 1;\n        else if (s3[i] == \"down\")\n            result = -1;\n        else\n            result = 0;\n        t1 = 1;\n    }\n    if (s2[i].rfind(ans) != -1)\n    {\n        if (s3[i] == \"up\")\n            result = -1;\n        else if (s3[i] == \"down\")\n            result = 1;\n        else\n            result = 0;\n        t2 = 1;\n    }\n    if (t1 == t2)\n    {\n        if (t1 == 1)\n            return 0;\n        return -2;\n    }\n    return result;\n}\n\nint main()\n{\n    int n, i, j, k, temp, sum;\n    char ans;\n    cin &gt;&gt; n;\n    while (n--)\n    {\n        for (i = 0; i &lt; 3; i++)\n            cin &gt;&gt; s1[i] &gt;&gt; s2[i] &gt;&gt; s3[i];\n        for (ans = 'A'; ans &lt;= 'L'; ans++)\n        {\n            temp = 0, sum = 0;\n            if ((f(ans, 0) == f(ans, 1) || f(ans, 0) == -2 || f(ans, 1) == -2) &amp;&amp; (f(ans, 1) == f(ans, 2) || f(ans, 1) == -2 || f(ans, 2) == -2) &amp;&amp; (f(ans, 0) == f(ans, 2) || f(ans, 0) == -2 || f(ans, 2) == -2))\n            {\n                for (j = 0; j &lt;= 2; j++)\n                    if (f(ans, j) != -2)\n                    {\n                        sum++;\n                        temp = f(ans, j);\n                    }\n                if (sum == 1) \/\/\u8fd9\u4e24\u4e2a\u5224\u65adsum\u7684\u975e\u5e38\u91cd\u8981\n                {\n                    int a1 = 0;\n                    for (j = 0; j &lt;= 2; j++)\n                        if (s3[j] == \"even\")\n                            a1++;\n                    if (a1 != 2)\n                        continue;\n                }\n                else if (sum == 2)\n                {\n                    int a1 = 0;\n                    for (j = 0; j &lt;= 2; j++)\n                        if (s3[j] == \"even\")\n                            a1++;\n                    if (a1 != 1)\n                        continue;\n                }\n                if (temp == -1)\n                {\n                    cout &lt;&lt; ans &lt;&lt; \" is the counterfeit coin and it is light.\" &lt;&lt; endl;\n                    break;\n                }\n                if (temp == 1)\n                {\n                    cout &lt;&lt; ans &lt;&lt; \" is the counterfeit coin and it is heavy.\" &lt;&lt; endl;\n                    break;\n                }\n            }\n        }\n    }\n    return 0;\n}\n<\/code><\/pre>\n<h4>\u6ce8\u610f\u4e8b\u9879<\/h4>\n<p>\u82e5\u7528\u679a\u4e3e\u505a\u6b64\u9898\uff0c\u60c5\u51b5\u8981\u8003\u8651\u5168\u9762\uff0c\u5148\u5728\u672c\u5730\u591a\u6d4b\u8bd5\u51e0\u79cd\u6570\u636e\uff08\u81ea\u5df1\u7f16\u6570\u636e\uff09\uff0c\u4e0d\u8981\u5c40\u9650\u4e8e\u9898\u76ee\u6240\u7ed9\u7684\u4e00\u4e2a\u6837\u4f8b\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u9898\u76ee\u5927\u610f 12\u679a\u786c\u5e01\u4e2d\u53ea\u67091\u679a\u5047\u5e01\uff0c\u5047\u5e01\u6bd4\u771f\u5e01\u8f7b\u6216\u8005\u6bd4\u771f\u5e01\u91cd\u3002\u7528\u5929\u5e73\u79f0\u4e86\u786c\u5e01\u4e09\u6b21\uff0c\u6bcf\u6b21\u5929\u5e73\u5de6\u8fb9\u7684\u786c\u5e01\u6570\u90fd\u548c\u53f3\u8fb9 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[25,53],"class_list":["post-33","post","type-post","status-publish","format-standard","hentry","category-algo","tag-poj","tag-53"],"_links":{"self":[{"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=\/wp\/v2\/posts\/33","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=33"}],"version-history":[{"count":0,"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=\/wp\/v2\/posts\/33\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=33"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=33"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=33"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}