{"id":207047,"date":"2025-07-08T10:44:30","date_gmt":"2025-07-08T02:44:30","guid":{"rendered":"https:\/\/server.hk\/cnblog\/207047\/"},"modified":"2025-07-08T10:44:30","modified_gmt":"2025-07-08T02:44:30","slug":"%e5%a6%82%e4%bd%95%e5%9c%a8-golang-%e4%b8%ad%e5%88%9b%e5%bb%ba%e5%9d%97%e7%9f%a9%e9%98%b5%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/207047\/","title":{"rendered":"\u5982\u4f55\u5728 Golang \u4e2d\u521b\u5efa\u5757\u77e9\u9635\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<p>\u5f53\u524d\u4f4d\u7f6e\uff1a <span>&gt;<\/span> <span>&gt;<\/span> <span>&gt;<\/span> <span>&gt;<\/span> <span>\u5982\u4f55\u5728 Golang \u4e2d\u521b\u5efa\u5757\u77e9\u9635\uff1f<\/span><\/p>\n<p><span>\u6765\u6e90\uff1astackoverflow<\/span><br \/>\n<span>2024-04-19 17:57:33<\/span><br \/>\n<span><i><\/i>0\u6d4f\u89c8<\/span><br \/>\n<span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>Golang\u5c0f\u767d\u4e00\u679a\uff0c\u6b63\u5728\u4e0d\u65ad\u5b66\u4e60\u79ef\u7d2f\u77e5\u8bc6\uff0c\u73b0\u5c06\u5b66\u4e60\u5230\u7684\u77e5\u8bc6\u8bb0\u5f55\u4e00\u4e0b\uff0c\u4e5f\u662f\u5c06\u6211\u7684\u6240\u5f97\u5206\u4eab\u7ed9\u5927\u5bb6\uff01\u800c\u4eca\u5929\u8fd9\u7bc7\u6587\u7ae0\u300a\u5982\u4f55\u5728 Golang \u4e2d\u521b\u5efa\u5757\u77e9\u9635\uff1f\u300b\u5e26\u5927\u5bb6\u6765\u4e86\u89e3\u4e00\u4e0b##content_title##\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff0c\u4ece\u800c\u5f25\u8865\u81ea\u5df1\u7684\u4e0d\u8db3\uff0c\u52a9\u529b\u5b9e\u6218\u5f00\u53d1\uff01<\/p>\n<p><\/p>\n<p> \u95ee\u9898\u5185\u5bb9<br \/>\n <\/p>\n<p>\u6211\u6b63\u5728\u5c1d\u8bd5\u521b\u5efa\u4e00\u4e2a\u5305\u542b 4 \u4e2a\u5757\uff08n*n \u5b50\u77e9\u9635\uff09\u7684\u5757\u77e9\u9635\u3002<\/p>\n<p>\u6211\u5c1d\u8bd5\u4e86\u5f88\u591a\u65b9\u6cd5\uff0c\u4f46\u65e0\u6cd5\u8ba9\u5b83\u53d1\u6325\u4f5c\u7528\u3002<\/p>\n<pre>func newBlocMatrix(A Matrix, B Matrix, C Matrix, D Matrix) (M Matrix) {\n    var M Matrix\n    \/\/ Something here\n\n    \/\/ Filled with A, B, C, and D\n\n    return M, nil\n}<\/pre>\n<p>\u7528\u77e9\u9635 a\u3001b\u3001c \u548c d \u586b\u5145\u77e9\u9635 m \u6709\u4ec0\u4e48\u5efa\u8bae\u5417\uff1f<\/p>\n<p> <\/p>\n<h2>\u89e3\u51b3\u65b9\u6848<\/h2>\n<p> <\/p>\n<p>\u4e3a\u7b80\u5355\u8d77\u89c1\uff0c\u6211\u5047\u8bbe <code>matrix<\/code> \u662f\u4e00\u4e2a\u6b63\u65b9\u5f62 (n*n) <code>[][]int<\/code>\uff1a<\/p>\n<pre>package main\n\nimport \"fmt\"\n\ntype matrix [][]int\n\nfunc block(a, b, c, d matrix) matrix {\n    l := len(a)\n    s := l * 2\n    m := make([][]int, s)\n    for i := 0; i &lt; s; i++ {\n        m[i] = make([]int, s)\n    }\n    copy(a, m, 0, 0)\n    copy(b, m, 0, l)\n    copy(c, m, l, 0)\n    copy(d, m, l, l)\n    return m\n}\n\nfunc copy(a, m matrix, x, y int) {\n    for i := 0; i &lt; len(a); i++ {\n        for j := 0; j &lt; len(a[i]); j++ {\n            m[i+x][j+y] = a[i][j]\n        }\n    }\n}\n\nfunc main() {\n    a := matrix{{1, 2}, {3, 4}}\n    b := matrix{{5, 6}, {7, 8}}\n    c := matrix{{9, 10}, {11, 12}}\n    d := matrix{{13, 14}, {15, 16}}\n    m := block(a, b, c, d)\n    fmt.printf(\"a: %+v\\n\", a)\n    fmt.printf(\"b: %+v\\n\", b)\n    fmt.printf(\"c: %+v\\n\", c)\n    fmt.printf(\"d: %+v\\n\", d)\n    fmt.printf(\"m: %+v\\n\", m)\n}\n<\/pre>\n<p>\u8fd0\u884c\u6253\u5370\uff1a<\/p>\n<pre>a: [[1 2] [3 4]]\nb: [[5 6] [7 8]]\nc: [[9 10] [11 12]]\nd: [[13 14] [15 16]]\nm: [[1 2 5 6] [3 4 7 8] [9 10 13 14] [11 12 15 16]]<\/pre>\n<p>\u6211\u76f8\u4fe1\u8fd9\u5c31\u662f\u4f60\u60f3\u8981\u7684\u3002<\/p>\n<p>\u4eca\u5929\u5e26\u5927\u5bb6\u4e86\u89e3\u4e86\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u5e0c\u671b\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\uff1b\u5173\u4e8eGolang\u7684\u6280\u672f\u77e5\u8bc6\u6211\u4eec\u4f1a\u4e00\u70b9\u70b9\u6df1\u5165\u4ecb\u7ecd\uff0c\u6b22\u8fce\u5927\u5bb6\u5173\u6ce8\u516c\u4f17\u53f7\uff0c\u4e00\u8d77\u5b66\u4e60\u7f16\u7a0b~<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5f53\u524d\u4f4d\u7f6e\uff1a &gt; &gt; &#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4925],"tags":[],"class_list":["post-207047","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/207047","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=207047"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/207047\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=207047"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=207047"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=207047"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}