{"id":6393,"date":"2024-08-09T19:01:01","date_gmt":"2024-08-09T11:01:01","guid":{"rendered":""},"modified":"2024-08-09T19:01:01","modified_gmt":"2024-08-09T11:01:01","slug":"\u7528\u9012\u5f52\u51fd\u6570\u8bbe\u8ba1\u516b\u7687\u540e\u95ee\u9898\u7684\u56de\u6eaf\u7b97\u6cd5_\u516b\u7687\u540e\u975e\u9012\u5f52\u7b97\u6cd5","status":"publish","type":"post","link":"https:\/\/mushiming.com\/6393.html","title":{"rendered":"\u7528\u9012\u5f52\u51fd\u6570\u8bbe\u8ba1\u516b\u7687\u540e\u95ee\u9898\u7684\u56de\u6eaf\u7b97\u6cd5_\u516b\u7687\u540e\u975e\u9012\u5f52\u7b97\u6cd5"},"content":{"rendered":"
\u4e00\uff1a\u516b\u7687\u540e\u95ee\u9898<\/p>\n
\u516b\u7687\u540e\u95ee\u9898\uff0c\u662f\u4e00\u4e2a\u53e4\u8001\u800c\u8457\u540d\u7684\u95ee\u9898\uff0c\u662f\u56de\u6eaf\u7b97\u6cd5\u7684\u5178\u578b\u6848\u4f8b\u3002\u8be5\u95ee\u9898\u662f\u56fd\u9645\u897f\u6d0b\u68cb\u68cb\u624b\u9a6c\u514b\u65af\u00b7\u8d1d\u745f\u5c14\u4e8e1848 \u5e74\u63d0\u51fa\uff1a\u5728 8\u00d78 \u683c\u7684\u56fd\u9645\u8c61\u68cb\u4e0a\u6446\u653e\u516b\u4e2a\u7687\u540e\uff0c\u4f7f\u5176\u4e0d\u80fd\u4e92\u76f8\u653b\u51fb\uff0c\u5373\uff1a\u4efb\u610f\u4e24\u4e2a\u7687\u540e\u90fd\u4e0d\u80fd\u5904\u4e8e\u540c\u4e00\u884c\u3001\u540c\u4e00\u5217\u6216\u540c\u4e00\u659c\u7ebf\u4e0a\uff0c\u95ee\u6709\u591a\u5c11\u79cd\u6446\u6cd5(92)<\/code><\/pre>\n<\/p>\n
\u7b97\u6cd5\u601d\u8def\uff1a<\/p>\n
\n- \u7b2c\u4e00\u4e2a\u7687\u540e\u5148\u653e\u7b2c\u4e00\u884c\u7b2c\u4e00\u5217\u3002<\/span><\/li>\n
- \u7b2c\u4e8c\u4e2a\u7687\u540e\u653e\u5728\u7b2c\u4e8c\u884c\u7b2c\u4e00\u5217\u3001\u7136\u540e\u5224\u65ad\u662f\u5426 <\/span>OK<\/span>\uff0c \u5982\u679c\u4e0d <\/span>OK<\/span>\uff0c\u7ee7\u7eed\u653e\u5728\u7b2c\u4e8c\u5217\u3001\u7b2c\u4e09\u5217\u3001\u4f9d\u6b21\u628a\u6240\u6709\u5217\u90fd<\/span>\u653e\u5b8c\uff0c\u627e\u5230\u4e00\u4e2a\u5408\u9002\u3002<\/span><\/li>\n
- \u7ee7\u7eed\u7b2c\u4e09\u4e2a\u7687\u540e\uff0c\u8fd8\u662f\u7b2c\u4e00\u5217\u3001\u7b2c\u4e8c\u5217\u2026\u2026\u76f4\u5230\u7b2c <\/span>8 <\/span>\u4e2a\u7687\u540e\u4e5f\u80fd\u653e\u5728\u4e00\u4e2a\u4e0d\u51b2\u7a81\u7684\u4f4d\u7f6e\uff0c\u7b97\u662f\u627e\u5230\u4e86\u4e00\u4e2a\u6b63\u786e<\/span>\u89e3\u3002<\/span><\/li>\n
- \u5f53\u5f97\u5230\u4e00\u4e2a\u6b63\u786e\u89e3\u65f6\uff0c\u5728\u6808\u56de\u9000\u5230\u4e0a\u4e00\u4e2a\u6808\u65f6\uff0c\u5c31\u4f1a\u5f00\u59cb\u56de\u6eaf\uff0c\u5373\u5c06\u7b2c\u4e00\u4e2a\u7687\u540e\uff0c\u653e\u5230\u7b2c\u4e00\u5217\u7684\u6240\u6709\u6b63\u786e\u89e3\uff0c<\/span>\u5168\u90e8\u5f97\u5230\u3002<\/span><\/li>\n
- \u7136\u540e\u56de\u5934\u7ee7\u7eed\u7b2c\u4e00\u4e2a\u7687\u540e\u653e\u7b2c\u4e8c\u5217\uff0c\u540e\u9762\u7ee7\u7eed\u5faa\u73af\u6267\u884c <\/span>1,2,3,4 <\/span>\u7684\u6b65\u9aa4\u3002<\/span><\/li>\n<\/ol>\n\n \u8bf4\u660e\uff1a <\/span>\n <\/div>\n\n \u7406\u8bba\u4e0a\u5e94\u8be5\u521b\u5efa\u4e00\u4e2a\u4e8c\u7ef4\u6570\u7ec4\u6765\u8868\u793a\u68cb\u76d8\uff0c\u4f46\u662f\u5b9e\u9645\u4e0a\u53ef\u4ee5\u901a\u8fc7\u7b97\u6cd5\uff0c\u7528\u4e00\u4e2a\u4e00\u7ef4\u6570\u7ec4\u5373\u53ef\u89e3\u51b3\u95ee\u9898<\/span>
\n . arr[8] = {0 , 4, 7, 5, 2, 6, 1, 3} \/\/\u5bf9\u5e94 <\/span>
\n arr <\/span>
\n \u4e0b\u6807 \u8868\u793a\u7b2c\u51e0\u884c\uff0c\u5373\u7b2c\u51e0\u4e2a\u7687\u540e\uff0c<\/span>
\n arr[i] = val , val <\/span>
\n \u8868\u793a\u7b2c <\/span>
\n i+1 <\/span>
\n \u4e2a\u7687\u540e\uff0c\u653e\u5728\u7b2c <\/span>
\n i+1 \u884c\u7684\u7b2c val+1 <\/span>
\n \u5217\u3002<\/span>\n <\/div>\n\nQueue8\u5b9e\u4f53\u7c7b<\/code><\/pre>\npackage com.recursion; \/** * @author lizhangyu * @date 2021\/3\/10 22:42 *\/ public class Queue8 { private int max = 8; private int[] arr = new int[max]; private static int judgeCount = 0; private static int count = 0; public static void main(String[] args) { Queue8 queue8 = new Queue8(); queue8.check(0); System.out.printf(\"\u4e00\u5171\u6709%d \u89e3\u6cd5\\n\", count); System.out.printf(\"\u4e00\u5171\u5224\u65ad\u51b2\u7a81\u7684\u6b21\u6570%d \u6b21\", judgeCount); } public void check(int n) { \/\/\u7ed3\u675f\u7684\u6761\u4ef6 if (n == 8) { print(); return; } for (int i = 0; i < max; i++) { \/\/\u5148\u628a\u5f53\u524d\u8fd9\u4e2a\u7687\u540en\uff0c\u653e\u5230\u8be5\u884c\u7684\u7b2c\u4e00\u5217 arr[n] = i; if (judge(n)) { check(n+1); } } } public boolean judge(int n) { judgeCount++; for (int i = 0; i < n; i++) { \/\/\u5224\u65ad\u662f\u5426\u5728\u540c\u4e00\u5217\u6216\u8005\u540c\u4e00\u659c\u7ebf\u4e0a if (arr[i] == arr[n] || Math.abs(i-n) == Math.abs(arr[i]-arr[n])) { return false; } } return true; } public void print() { count++; for (int i = 0; i < arr.length; i++) { System.out.print(arr[i] + \" \"); } System.out.println(); } } <\/code><\/pre>\n\u8fd0\u884c\u7684\u7ed3\u679c\uff1a<\/p>\n
0 4 7 5 2 6 1 3 0 5 7 2 6 3 1 4 0 6 3 5 7 1 4 2 0 6 4 7 1 3 5 2 1 3 5 7 2 0 6 4 1 4 6 0 2 7 5 3 1 4 6 3 0 7 5 2 1 5 0 6 3 7 2 4 1 5 7 2 0 3 6 4 1 6 2 5 7 4 0 3 1 6 4 7 0 3 5 2 1 7 5 0 2 4 6 3 2 0 6 4 7 1 3 5 2 4 1 7 0 6 3 5 2 4 1 7 5 3 6 0 2 4 6 0 3 1 7 5 2 4 7 3 0 6 1 5 2 5 1 4 7 0 6 3 2 5 1 6 0 3 7 4 2 5 1 6 4 0 7 3 2 5 3 0 7 4 6 1 2 5 3 1 7 4 6 0 2 5 7 0 3 6 4 1 2 5 7 0 4 6 1 3 2 5 7 1 3 0 6 4 2 6 1 7 4 0 3 5 2 6 1 7 5 3 0 4 2 7 3 6 0 5 1 4 3 0 4 7 1 6 2 5 3 0 4 7 5 2 6 1 3 1 4 7 5 0 2 6 3 1 6 2 5 7 0 4 3 1 6 2 5 7 4 0 3 1 6 4 0 7 5 2 3 1 7 4 6 0 2 5 3 1 7 5 0 2 4 6 3 5 0 4 1 7 2 6 3 5 7 1 6 0 2 4 3 5 7 2 0 6 4 1 3 6 0 7 4 1 5 2 3 6 2 7 1 4 0 5 3 6 4 1 5 0 2 7 3 6 4 2 0 5 7 1 3 7 0 2 5 1 6 4 3 7 0 4 6 1 5 2 3 7 4 2 0 6 1 5 4 0 3 5 7 1 6 2 4 0 7 3 1 6 2 5 4 0 7 5 2 6 1 3 4 1 3 5 7 2 0 6 4 1 3 6 2 7 5 0 4 1 5 0 6 3 7 2 4 1 7 0 3 6 2 5 4 2 0 5 7 1 3 6 4 2 0 6 1 7 5 3 4 2 7 3 6 0 5 1 4 6 0 2 7 5 3 1 4 6 0 3 1 7 5 2 4 6 1 3 7 0 2 5 4 6 1 5 2 0 3 7 4 6 1 5 2 0 7 3 4 6 3 0 2 7 5 1 4 7 3 0 2 5 1 6 4 7 3 0 6 1 5 2 5 0 4 1 7 2 6 3 5 1 6 0 2 4 7 3 5 1 6 0 3 7 4 2 5 2 0 6 4 7 1 3 5 2 0 7 3 1 6 4 5 2 0 7 4 1 3 6 5 2 4 6 0 3 1 7 5 2 4 7 0 3 1 6 5 2 6 1 3 7 0 4 5 2 6 1 7 4 0 3 5 2 6 3 0 7 1 4 5 3 0 4 7 1 6 2 5 3 1 7 4 6 0 2 5 3 6 0 2 4 1 7 5 3 6 0 7 1 4 2 5 7 1 3 0 6 4 2 6 0 2 7 5 3 1 4 6 1 3 0 7 4 2 5 6 1 5 2 0 3 7 4 6 2 0 5 7 4 1 3 6 2 7 1 4 0 5 3 6 3 1 4 7 0 2 5 6 3 1 7 5 0 2 4 6 4 2 0 5 7 1 3 7 1 3 0 6 4 2 5 7 1 4 2 0 6 3 5 7 2 0 5 1 4 6 3 7 3 0 2 5 1 6 4 \u4e00\u5171\u670992 \u89e3\u6cd5 \u4e00\u5171\u5224\u65ad\u51b2\u7a81\u7684\u6b21\u657015720 \u6b21<\/code><\/pre>\n <\/p>\n<\/p><\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"\u7528\u9012\u5f52\u51fd\u6570\u8bbe\u8ba1\u516b\u7687\u540e\u95ee\u9898\u7684\u56de\u6eaf\u7b97\u6cd5_\u516b\u7687\u540e\u975e\u9012\u5f52\u7b97\u6cd5\u4e00\uff1a\u516b\u7687\u540e\u95ee\u9898\u516b\u7687\u540e\u95ee\u9898\uff0c\u662f\u4e00\u4e2a\u53e4\u8001\u800c\u8457\u540d\u7684\u95ee\u9898\uff0c\u662f\u56de\u6eaf\u7b97\u6cd5\u7684\u5178\u578b...","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"_links":{"self":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/6393"}],"collection":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/comments?post=6393"}],"version-history":[{"count":0,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/6393\/revisions"}],"wp:attachment":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/media?parent=6393"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/categories?post=6393"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/tags?post=6393"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}