{"id":321,"date":"2011-10-18T14:16:45","date_gmt":"2011-10-18T06:16:45","guid":{"rendered":"http:\/\/wangkaixuan.tech\/?p=321"},"modified":"2020-06-06T14:18:18","modified_gmt":"2020-06-06T06:18:18","slug":"%e6%95%b0%e7%bb%84%e4%b8%8e%e5%b9%bf%e4%b9%89%e8%a1%a8_%e7%a8%80%e7%96%8f%e7%9f%a9%e9%98%b5%e7%9a%84%e5%8e%8b%e7%bc%a9%e5%ad%98%e5%82%a8_%e4%b8%89%e5%85%83%e7%bb%84%e5%81%9a%e5%ad%98%e5%82%a8-2","status":"publish","type":"post","link":"http:\/\/www.wangkaixuan.tech\/?p=321","title":{"rendered":"\u6570\u7ec4\u4e0e\u5e7f\u4e49\u8868_\u7a00\u758f\u77e9\u9635\u7684\u538b\u7f29\u5b58\u50a8_\u4e09\u5143\u7ec4\u505a\u5b58\u50a8\u7ed3\u6784_\u77e9\u9635\u76f8\u4e58"},"content":{"rendered":"\n<p>head.h<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include&lt;iostream>\nusing namespace std;\n\n#define MAX_MATRIXSIZE 20\n#define ElemType int\n\nclass Triple \/\/\u4e09\u5143\u7ec4\u7c7b\n{\npublic:\n\tint i, j; \/\/\u884c\u5217\u53f7\n\tElemType e; \/\/\u5143\u7d20\u503c\n};\n\nclass TSMatrix \/\/\u77e9\u9635\u7c7b\n{\npublic:\n\tTriple matrix&#91;MAX_MATRIXSIZE]; \/\/\u4e09\u5143\u7ec4\u96c6\u5408 \n\tint mu, nu, tu; \/\/\u884c\u6570\uff0c\u5217\u6570\uff0c\u975e\u96f6\u5143\u4e2a\u6570\n};\n\nclass Matrix \/\/\u77e9\u9635\u7c7b\u5c01\u88c5\u4e86\u6709\u5173\u77e9\u9635\u7684\u64cd\u4f5c\n{\npublic:\n\tvoid MatrixMutiply(); \/\/\u63a5\u53e3\u51fd\u6570\nprivate:\n\tvoid GetMatrix(); \/\/\u5f97\u5230\u77e9\u9635\u7684\u4e09\u5143\u7ec4\n\tvoid Mutiply(); \/\/\u77e9\u9635\u76f8\u4e58\n\tvoid PrintMatrix(TSMatrix&amp;); \/\/\u6253\u5370\u77e9\u9635\n\tvoid GetCpot(int&#91;], TSMatrix&amp;); \/\/\u6c42\u5f97\u8f85\u52a9\u6570\u7ec4Cpot\u7684\u503c\/\/Cpot&#91;i]\u4ee3\u8868\u884c\u53f7\u4e3ai\u7684\u7b2c\u4e00\u4e2a\u5143\u7d20\u5728\u4e09\u5143\u7ec4\u4e2d\u7684\u4f4d\u7f6e\n\tTSMatrix m, n, q; \/\/\u5b9e\u4f8b\u5316\u77e9\u9635\u7c7b\u7684\u5bf9\u8c61\n};\n\nvoid Matrix::MatrixMutiply() \/\/\u63a5\u53e3\u51fd\u6570\n{\n\tGetMatrix();\n\tMutiply();\n\tPrintMatrix(m);\n\tPrintMatrix(n);\n\tPrintMatrix(q);\n}\n\nvoid Matrix::GetMatrix() \/\/\u5f97\u5230\u77e9\u9635M,N\u7684\u4e09\u5143\u7ec4\n{\n\tchar name&#91;2] =\n\t{ 'M', 'N' };\n\tTSMatrix *M&#91;2] =\n\t{ &amp;m, &amp;n };\n\tfor (int c = 0; c &lt; 2; c++)\n\t{\n\t\tcout &lt;&lt; \"Please Input The Size Of The Matrix \" &lt;&lt; name&#91;c] &lt;&lt; \"(m*n)\"\n\t\t\t\t&lt;&lt; endl;\n\t\tcin >> M&#91;c]->mu >> M&#91;c]->nu;\n\t\tM&#91;c]->tu = 1;\n\t\tcout &lt;&lt; \"Please Input Matrix With Increasing Order Of RowNumber\" &lt;&lt; endl\n\t\t\t\t&lt;&lt; \"rownum columnnum element\" &lt;&lt; endl &lt;&lt; endl;\n\t\tint i, j;\n\t\tElemType e;\n\t\twhile (cin >> i >> j >> e)\n\t\t{\n\t\t\tM&#91;c]->matrix&#91;M&#91;c]->tu].i = i;\n\t\t\tM&#91;c]->matrix&#91;M&#91;c]->tu].j = j;\n\t\t\tM&#91;c]->matrix&#91;M&#91;c]->tu].e = e;\n\t\t\tM&#91;c]->tu++;\n\t\t}\n\t\tcin.clear();\n\t}\n}\n\nvoid Matrix::GetCpot(int Cpot&#91;], TSMatrix &amp;t) \/\/\u6c42\u5f97\u8f85\u52a9\u6570\u7ec4Cpot\u7684\u503c\/\/Cpot&#91;i]\u4ee3\u8868\u884c\u53f7\u4e3ai\u7684\u7b2c\u4e00\u4e2a\u5143\u7d20\u5728\u4e09\u5143\u7ec4\u4e2d\u7684\u4f4d\u7f6e\n{\n\tint num&#91;MAX_MATRIXSIZE];\n\tmemset(num, 0, sizeof(num));\n\tfor (int i = 1; i &lt; t.tu; i++)\n\t\tnum&#91;t.matrix&#91;i].i]++;\n\tCpot&#91;1] = 1;\n\tfor (int i = 2; i &lt;= t.mu + 1; i++)\n\t\tCpot&#91;i] = Cpot&#91;i - 1] + num&#91;i - 1];\n}\n\nvoid Matrix::Mutiply()\n{\n\tint cpotm&#91;MAX_MATRIXSIZE], cpotn&#91;MAX_MATRIXSIZE];\n\tGetCpot(cpotm, m);\n\tGetCpot(cpotn, n);\n\tint temp&#91;MAX_MATRIXSIZE];\n\tq.tu = 1;\n\tfor (int i = 1; i &lt; m.tu; i = cpotm&#91;m.matrix&#91;i].i + 1])\n\t{\n\t\tmemset(temp, 0, sizeof(temp));\n\t\tfor (int j = i; j &lt; cpotm&#91;m.matrix&#91;i].i + 1]; j++)\n\t\t{\n\t\t\tfor (int k = cpotn&#91;m.matrix&#91;j].j]; k &lt; cpotn&#91;m.matrix&#91;j].j + 1];\n\t\t\t\t\tk++)\n\t\t\t\ttemp&#91;n.matrix&#91;k].j] += m.matrix&#91;j].e * n.matrix&#91;k].e;\n\t\t}\n\t\tfor (int j = 1; j &lt;= n.nu; j++)\n\t\t{\n\t\t\tif (temp&#91;j] != 0)\n\t\t\t{\n\t\t\t\tq.matrix&#91;q.tu].i = m.matrix&#91;i].i;\n\t\t\t\tq.matrix&#91;q.tu].j = j;\n\t\t\t\tq.matrix&#91;q.tu].e = temp&#91;j];\n\t\t\t\tq.tu++;\n\t\t\t}\n\t\t}\n\t}\n}\n\nvoid Matrix::PrintMatrix(TSMatrix &amp;t) \/\/\u6253\u5370\u77e9\u9635\n{\n\tfor (int i = 1; i &lt; t.tu; i++)\n\t\tcout &lt;&lt; t.matrix&#91;i].i &lt;&lt; \" \" &lt;&lt; t.matrix&#91;i].j &lt;&lt; \" \" &lt;&lt; t.matrix&#91;i].e\n\t\t\t\t&lt;&lt; endl;\n\tcout &lt;&lt; endl;\n}\n<\/code><\/pre>\n\n\n\n<p>main.cpp<\/p>\n\n\n\n<p>*\u4ee3\u7801\u4e22\u5931\u3002\u3002\u3002\u5f85\u8865\u5145<\/p>\n","protected":false},"excerpt":{"rendered":"<p>head.h main.cpp *\u4ee3\u7801\u4e22\u5931\u3002\u3002\u3002\u5f85\u8865\u5145<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"class_list":["post-321","post","type-post","status-publish","format-standard","hentry","category-06-02-"],"_links":{"self":[{"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=\/wp\/v2\/posts\/321","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=321"}],"version-history":[{"count":0,"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=\/wp\/v2\/posts\/321\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=321"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=321"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=321"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}