{"id":1194,"date":"2022-05-29T09:08:04","date_gmt":"2022-05-29T01:08:04","guid":{"rendered":"https:\/\/sanlangcode.com\/?p=1194"},"modified":"2022-05-29T09:08:04","modified_gmt":"2022-05-29T01:08:04","slug":"hj67-24%e7%82%b9%e6%b8%b8%e6%88%8f%e7%ae%97%e6%b3%95","status":"publish","type":"post","link":"https:\/\/sanlangcode.com\/index.php\/2022\/05\/29\/hj67-24%e7%82%b9%e6%b8%b8%e6%88%8f%e7%ae%97%e6%b3%95\/","title":{"rendered":"HJ67 24\u70b9\u6e38\u620f\u7b97\u6cd5"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">\u63cf\u8ff0<\/h2>\n\n\n\n<p>\u7ed9\u51fa4\u4e2a1-10\u7684\u6570\u5b57\uff0c\u901a\u8fc7\u52a0\u51cf\u4e58\u9664\u8fd0\u7b97\uff0c\u5f97\u5230\u6570\u5b57\u4e3a24\u5c31\u7b97\u80dc\u5229,\u9664\u6cd5\u6307\u5b9e\u6570\u9664\u6cd5\u8fd0\u7b97,\u8fd0\u7b97\u7b26\u4ec5\u5141\u8bb8\u51fa\u73b0\u5728\u4e24\u4e2a\u6570\u5b57\u4e4b\u95f4,\u672c\u9898\u5bf9\u6570\u5b57\u9009\u53d6\u987a\u5e8f\u65e0\u8981\u6c42\uff0c\u4f46\u6bcf\u4e2a\u6570\u5b57\u4ec5\u5141\u8bb8\u4f7f\u7528\u4e00\u6b21\uff0c\u4e14\u9700\u8003\u8651\u62ec\u53f7\u8fd0\u7b97\u6b64\u9898\u5141\u8bb8\u6570\u5b57\u91cd\u590d\uff0c\u59823 3 4 4\u4e3a\u5408\u6cd5\u8f93\u5165\uff0c\u6b64\u8f93\u5165\u4e00\u5171\u6709\u4e24\u4e2a3\uff0c\u4f46\u662f\u6bcf\u4e2a\u6570\u5b57\u53ea\u5141\u8bb8\u4f7f\u7528\u4e00\u6b21\uff0c\u5219\u8fd0\u7b97\u8fc7\u7a0b\u4e2d\u4e24\u4e2a3\u90fd\u88ab\u9009\u53d6\u5e76\u8fdb\u884c\u5bf9\u5e94\u7684\u8ba1\u7b97\u64cd\u4f5c\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u8f93\u5165\u63cf\u8ff0\uff1a<\/h3>\n\n\n\n<p>\u8bfb\u51654\u4e2a[1,10]\u7684\u6574\u6570\uff0c\u6570\u5b57\u5141\u8bb8\u91cd\u590d\uff0c\u6d4b\u8bd5\u7528\u4f8b\u4fdd\u8bc1\u65e0\u5f02\u5e38\u6570\u5b57\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u8f93\u51fa\u63cf\u8ff0\uff1a<\/h3>\n\n\n\n<p>\u5bf9\u4e8e\u6bcf\u7ec4\u6848\u4f8b\uff0c\u8f93\u51fa\u4e00\u884c\u8868\u793a\u80fd\u5426\u5f97\u523024\u70b9\uff0c\u80fd\u8f93\u51fatrue\uff0c\u4e0d\u80fd\u8f93\u51fafalse<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u793a\u4f8b1<\/h2>\n\n\n\n<p>\u8f93\u5165\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">7 2 1 10<\/pre>\n\n\n\n<p>\u590d\u5236\u8f93\u51fa\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">true<\/pre>\n\n\n<p><strong>\u7b97\u6cd5\u6d41\u7a0b<\/strong>\uff1a<\/p>\n<ul>\n<li>\u901a\u8fc7\u9012\u5f52+dfs\uff0c\u9996\u5148\u5b9a\u4e49\u9012\u5f52\u51fd\u6570\u529f\u80fd\uff1a\u5f53\u524d\u5df2\u7ecf\u4f7f\u7528\u4e86\u6570\u7ec4\u7684u\u4e2a\u6570\u5b57\uff0c\u524d\u9762\u6570\u5b57\u7684\u8fd0\u7b97\u7ed3\u679c\u4e3atmp\uff0c\u8fd4\u56de\u662f\u5426\u8fd0\u7b97\u7ed3\u679c\u4e3a24<\/li>\n<li>\u786e\u5b9a\u9012\u5f52\u7ec8\u6b62\u6761\u4ef6\uff1a\u5df2\u7ecf\u4f7f\u7528\u4e86\u6570\u7ec4\u56db\u4e2a\u5143\u7d20\uff0c\u540c\u65f6\u7ed3\u679c\u4e3a24\uff0c\u6ee1\u8db3\u9898\u610f<\/li>\n<li>\u901a\u8fc7\u52a0\u51cf\u4e58\u9664\u56db\u79cd\u8fd0\u7b97\uff0c\u52a0\u51cf\u4e58\u9664\u5f53\u524d\u6570\u5b57num[i]\uff0c\u4e0d\u65ad\u9012\u5f52\u8fd0\u7b97\uff0c\u76f4\u5230\u5df2\u7ecf\u4f7f\u7528\u4e86\u6570\u7ec4\u56db\u4e2a\u5143\u7d20\uff0c\u540c\u65f6\u7ed3\u679c\u4e3a24\uff0c\u6ee1\u8db3\u9898\u610f<\/li>\n<\/ul>\n\n<pre class=\"lang:java decode:true \">import java.util.*;\nimport java.io.*;\npublic class Main{\n    static int[] nums = new int[4];\n    static boolean[] visit = new boolean[4];\n    static int flag = 0;\n    \n    public static void main(String[] args){\n        Scanner in = new Scanner(System.in);\n        while(in.hasNext()){\n            String[] a = in.nextLine().split(\" \");\n            for(int i = 0; i &lt; 4; i ++)\n                nums[i] = Integer.parseInt(a[i]);\n            dfs(0, 0);   \n            System.out.println( flag == 1 );\n        }\n\n    }\n\n    \/\/ tmp\u662f\u524d\u9762n\u4e2a\u6570\u5b57\u8fd0\u7b97\u7ed3\u679c\uff0cu\u8868\u793a\u5df2\u7ecf\u4f7f\u7528\u4e86\u591a\u5c11\u4e2a\u6570\u5b57\n    static boolean dfs(int u,float tmp){\n        \/\/ \u9012\u5f52\u7ec8\u6b62\u6761\u4ef6\uff1a\u5df2\u7ecf\u4f7f\u7528\u4e86\u6570\u7ec4\u56db\u4e2a\u5143\u7d20\uff0c\u540c\u65f6\u7ed3\u679c\u4e3a24\uff0c\u6ee1\u8db3\u9898\u610f\n        if(tmp == 24 &amp;&amp; u == 4){\n            flag = 1;\n            return true;\n        }\n\n        for(int i = 0; i &lt; 4; i ++){\n            if(visit[i] == false){\n                visit[i] = true;\n                \/\/ \u52a0\u51cf\u4e58\u9664\u5f53\u524d\u6570\u5b57num[i]\n                if( dfs(u + 1, tmp + nums[i]) ||\n                   dfs(u + 1, tmp - nums[i])  ||\n                   dfs(u + 1,tmp * nums[i]) ||\n                   dfs(u + 1, tmp \/ nums[i])){\n                    return true;\n                }\n                \/\/ \u76f8\u5f53\u4e8e\u56de\u6eaf\n                visit[i] = false;\n            }\n        }\n        return false;\n    }\n}\n\n\n<\/pre>\n<p>\u00a0<\/p>","protected":false},"excerpt":{"rendered":"<p>\u63cf\u8ff0 \u7ed9\u51fa4\u4e2a1-10\u7684\u6570\u5b57\uff0c\u901a&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":1122,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-1194","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-4"],"_links":{"self":[{"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/posts\/1194","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/comments?post=1194"}],"version-history":[{"count":0,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/posts\/1194\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/media\/1122"}],"wp:attachment":[{"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/media?parent=1194"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/categories?post=1194"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/tags?post=1194"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}