{"id":202,"date":"2024-10-16T12:16:53","date_gmt":"2024-10-16T04:16:53","guid":{"rendered":"https:\/\/www.xxinran.tech\/?p=202"},"modified":"2024-10-18T15:47:35","modified_gmt":"2024-10-18T07:47:35","slug":"c%e8%af%ad%e8%a8%80%e6%95%b0%e6%8d%ae%e7%bb%93%e6%9e%84-%e7%ba%bf%e6%80%a7%e8%a1%a8%e7%9a%84%e5%ba%94%e7%94%a8","status":"publish","type":"post","link":"https:\/\/www.xxinran.tech\/index.php\/2024\/10\/16\/c%e8%af%ad%e8%a8%80%e6%95%b0%e6%8d%ae%e7%bb%93%e6%9e%84-%e7%ba%bf%e6%80%a7%e8%a1%a8%e7%9a%84%e5%ba%94%e7%94%a8\/","title":{"rendered":"C\u8bed\u8a00\u6570\u636e\u7ed3\u6784\u2014\u2014\u7ebf\u6027\u8868\u7684\u5e94\u7528"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">\u524d\u8a00<\/h2>\n\n\n\n<p>\u8fd9\u7bc7\u7b97\u662f\u5bf9\u7ebf\u6027\u8868\u7684\u7b97\u6cd5\u7684\u8865\u5145\uff0c\u5b66\u5b8c\u524d\u4e24\u7bc7\u4e4b\u540e\u624d\u53ef\u4ee5\u770b\u8fd9\u4e00\u7bc7\u3002\u5176\u4e2d\u6709\u51e0\u4e2a\u64cd\u4f5c\u524d\u51e0\u7bc7\u6587\u7ae0\u63d0\u5230\u8fc7\uff0c\u4f46\u662f\u8fd9\u91cc\u8fd8\u662f\u8981\u5728\u63d0\u4e00\u6b21\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u7ebf\u6027\u8868\u7684\u5408\u5e76<\/h2>\n\n\n\n<p>\u8fd9\u4e2a\u7ebf\u6027\u8868\u7684\u5408\u5e76\u4e3e\u4e2a\u7b80\u5355\u7684\u4f8b\u5b50\u5c31\u662f\u6709\u4e24\u4e2a\u96c6\u5408A\uff0cB\uff0c\u6c42AUB\uff0c\u4e14\u4e0d\u6309\u6570\u636e\u5927\u5c0f\u6392\u5e8f\u3002<\/p>\n\n\n\n<p>\u7b97\u6cd5\u6b65\u9aa4<\/p>\n\n\n\n<p>\u2460\u5206\u8fa8\u83b7\u53d6L1\u7684\u8868\u957f\u548cL2\u7684\u8868\u957f\u3002<\/p>\n\n\n\n<p>\u2461\u4eceL2\u4e2d\u7684\u7b2c1\u4e2a\u6570\u636e\u5143\u7d20\u5f00\u59cb\uff0c\u5faa\u73afL2.length\u6b21\u6267\u884c\u4ee5\u4e0b\u64cd\u4f5c\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u4eceL2\u4e2d\u67e5\u627e\u7b2c<strong>i<\/strong>\u4e2a\u6570\u636e\u5143\u7d20\uff081\u2264<strong>i<\/strong>\u2264L2.length\uff09\u4e2a\u6570\u636e\u5143\u7d20\u8d4b\u7ed9e\uff1b<\/li>\n\n\n\n<li>\u5728L1\u4e2d\u67e5\u627e\u5143\u7d20e\uff0c\u5982\u679c\u4e0d\u5b58\u5728\uff0c\u5219\u5c06e\u63d2\u5728\u8868L1\u7684\u6700\u540e\u3002<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>void MergeList(List&amp; L1, List&amp; L2) {\n\t\/\/\u5c06\u6240\u6709\u5728L2\u4e2d\u4f46\u4e0d\u5728L1\u4e2d\u7684\u5143\u7d20\u63d2\u5165\u5230L1\u4e2d\n\tfor (int i = 1; i &lt;= L2.length; i++) {\n\t\tGetElem(L2, i, e);           \/\/\u53d6L2\u4e2d\u7b2ci\u4e2a\u6570\u636e\u5143\u7d20\u8d4b\u7ed9e\n\t\tif (!LocateElem(L1, e));     \/\/L1\u4e2d\u4e0d\u5b58\u5728\u548ce\u76f8\u540c\u7684\u6570\u636e\u5143\u7d20\n\t\tListInsert(L1, L1.length, e);\/\/\u5c06e\u63d2\u5728L1\u7684\u6700\u540e\n\t}\n}<\/code><\/pre>\n\n\n\n<p><strong>\u65f6\u95f4\u590d\u6742\u5ea6<\/strong>\uff1a\u2460\u5f53\u91c7\u7528\u987a\u5e8f\u5b58\u50a8\u7ed3\u6784\u65f6\uff0c\u5728\u6bcf\u6b21\u5faa\u73af\u4e2d\uff0cGetElem\u548cListInsert\u8fd9\u4e24\u4e2a\u64cd\u4f5c\u6240\u6267\u884c\u7684\u65f6\u95f4\u548c\u8868\u957f\u65e0\u5173\uff0cLocateElem\u7684\u6267\u884c\u65f6\u95f4\u548c\u8868\u957fL1.length\u6210\u6b63\u6bd4\uff0c\u56e0\u6b64\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3aO\uff08L1.length*L2.length\uff09\uff1b<\/p>\n\n\n\n<p>\u2461\u5f53\u91c7\u7528\u94fe\u5f0f\u7ed3\u6784\u65f6\uff0c\u5728\u6bcf\u6b21\u5faa\u73af\u4e2d\uff0cGetElem\u7684\u6267\u884c\u65f6\u95f4\u548c\u8868\u957fL2.length\u6210\u6b63\u6bd4\uff0c\u800cLocateElem\u548cListInsert\u8fd9\u4e24\u4e2a\u64cd\u4f5c\u7684\u6267\u884c\u65f6\u95f4\u548c\u8868\u957fL1.length\u6210\u53cd\u6bd4\uff0c\u56e0\u6b64\uff0c\u5047\u8bbeL1.length\u5927\u4e8eL2.length\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3aO\uff08L1.length*L2.length\uff09\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u6709\u5e8f\u8868\u7684\u5408\u5e76<\/h2>\n\n\n\n<p>\u8fd9\u4e2a\u548c\u4e0a\u4e00\u4e2a\u7b97\u6cd5\u7ebf\u6027\u8868\u7684\u5408\u5e76\u53ea\u76f8\u5dee\u5728\u6570\u636e\u5143\u7d20\u662f\u5426\u6709\u5e8f\u6392\u5217\uff0c\u76f8\u5f53\u4e8e\u662f\u96c6\u5408A\uff0cB\u6c42AUB\uff0c\u4e14AUB\u7684\u6570\u636e\u5143\u7d20\u662f\u6309\u7167\u5927\u5c0f\u987a\u5e8f\u6392\u5217\u7684\u4e14\u9047\u5230\u76f8\u540c\u7684\u6570\u636e\u5143\u7d20\u90fd\u7559\u4e0b\u6765\u3002<\/p>\n\n\n\n<p>\u6709\u5e8f\u8868\u7684\u5408\u5e76\u5206\u4e3a\u987a\u5e8f\u8868\u7684\u5408\u5e76\u548c\u94fe\u8868\u7684\u5408\u5e76\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u987a\u5e8f\u6709\u5e8f\u8868\u7684\u5408\u5e76<\/h3>\n\n\n\n<p>\u7b97\u6cd5\u6b65\u9aa4<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u521d\u59cb\u5316<\/strong>\uff1a\n<ul class=\"wp-block-list\">\n<li>\u521d\u59cb\u5316\u4e09\u4e2a\u6307\u9488&nbsp;<code>i<\/code>,&nbsp;<code>j<\/code>,&nbsp;<code>k<\/code>&nbsp;\u5206\u522b\u6307\u5411&nbsp;L1&nbsp;\u7684\u8d77\u59cb\u4f4d\u7f6e\u3001<code>L2<\/code>&nbsp;\u7684\u8d77\u59cb\u4f4d\u7f6e\u548c\u987a\u5e8f\u8868&nbsp;L3&nbsp;\u7684\u8d77\u59cb\u4f4d\u7f6e\u3002<\/li>\n\n\n\n<li><code>i = 0<\/code>,&nbsp;<code>j = 0<\/code>,&nbsp;<code>k = 0<\/code>\u3002<\/li>\n\n\n\n<li>\u5176\u4e2d\u8868L3\u7684\u8868\u957f\u4e3aL1\u8868\u957f\u548cL2\u8868\u957f\u7684\u548c\u3002<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>\u6bd4\u8f83\u4e0e\u63d2\u5165<\/strong>\uff1a\n<ul class=\"wp-block-list\">\n<li>\u6bd4\u8f83&nbsp;<code>L1[i]<\/code>&nbsp;\u548c&nbsp;<code>L2[j]<\/code>&nbsp;\u7684\u503c\u3002<\/li>\n\n\n\n<li>\u5982\u679c&nbsp;<code>L1[i] &lt;= L2[j]<\/code>\uff0c\u5219\u5c06&nbsp;<code>L1[i]<\/code>&nbsp;\u653e\u5165&nbsp;<code>L3[k]<\/code>\uff0c\u5e76\u5c06&nbsp;<code>i<\/code>&nbsp;\u548c&nbsp;<code>k<\/code>&nbsp;\u5404\u81ea\u52a01\u3002<\/li>\n\n\n\n<li>\u5426\u5219\uff0c\u5c06&nbsp;<code>L2[j]<\/code>&nbsp;\u653e\u5165&nbsp;<code>L3[k]<\/code>\uff0c\u5e76\u5c06&nbsp;<code>j<\/code>&nbsp;\u548c&nbsp;<code>k<\/code>&nbsp;\u5404\u81ea\u52a01\u3002<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>\u91cd\u590d<\/strong>\uff1a\n<ul class=\"wp-block-list\">\n<li>\u91cd\u590d\u4e0a\u8ff0\u6bd4\u8f83\u4e0e\u63d2\u5165\u7684\u8fc7\u7a0b\uff0c\u76f4\u5230\u5176\u4e2d\u4e00\u4e2a\u6570\u7ec4\u7684\u6240\u6709\u5143\u7d20\u90fd\u88ab\u5904\u7406\u5b8c\u3002<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>\u5269\u4f59\u5143\u7d20\u5904\u7406<\/strong>\uff1a\n<ul class=\"wp-block-list\">\n<li>\u5982\u679c&nbsp;L1&nbsp;\u4e2d\u8fd8\u6709\u5269\u4f59\u5143\u7d20\uff08\u5373&nbsp;<code>i &lt; m<\/code>\uff09\uff0c\u5219\u5c06&nbsp;L1&nbsp;\u4e2d\u5269\u4f59\u7684\u5143\u7d20\u4f9d\u6b21\u653e\u5165&nbsp;L3 \u4e2d\u3002<\/li>\n\n\n\n<li>\u5982\u679c&nbsp;L2&nbsp;\u4e2d\u8fd8\u6709\u5269\u4f59\u5143\u7d20\uff08\u5373&nbsp;<code>j &lt; n<\/code>\uff09\uff0c\u5219\u5c06&nbsp;L2&nbsp;\u4e2d\u5269\u4f59\u7684\u5143\u7d20\u4f9d\u6b21\u653e\u5165&nbsp;L3 \u4e2d\u3002<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>\u5b8c\u6210<\/strong>\uff1a\n<ul class=\"wp-block-list\">\n<li>\u5f53\u4e24\u4e2a\u987a\u5e8f\u8868\u7684\u6240\u6709\u5143\u7d20\u90fd\u88ab\u5904\u7406\u5b8c\u6bd5\u540e\uff0c\u5408\u5e76\u8fc7\u7a0b\u7ed3\u675f\uff0cL3&nbsp;\u5373\u4e3a\u6700\u7ec8\u7684\u5408\u5e76\u8868\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>int Merge(SqList &amp;L1,SqList &amp;L2){\n\tSqList L3;\n\tL3.elem=new ElemType&#91;L1.length+L2.length];\n\tif(L3.elem==NULL){\n\t\treturn ERROR;\n\t}\n\tint i=0,j=0,k=0;\n\twhile(i&lt;L1.length&amp;&amp;j&lt;L2.length){\n\t\tif(L1.elem&#91;i]&lt;=L2.elem&#91;j]) {\n\t\t\tL3.elem&#91;k++]=L1.elem&#91;i++];\n\t\t}\n\t\telse{\n\t\t\tL3.elem&#91;k++]=L2.elem&#91;j++];\n\t\t}\n\t}\n\t\/\/\u590d\u5236L1\u4e2d\u5269\u4f59\u7684\u5143\u7d20\n\twhile(i&lt;L1.length){\n\t\tL3.elem&#91;k++]=L1.elem&#91;i++];\n\t} \n\t\/\/\u590d\u5236L2\u4e2d\u5269\u4f59\u7684\u5143\u7d20\n\twhile(j&lt;L2.length){\n\t\tL3.elem&#91;k++] = L2.elem&#91;j++];\n\t} \n\tL3.length = k;\n\tfor (i = 0; i &lt; L3.length; i++) {\n\t\tcout &lt;&lt; L3.elem&#91;i] &lt;&lt; endl;\n\t}\n\treturn 0;\n}<\/code><\/pre>\n\n\n\n<p><strong>\u987a\u5e8f\u8868<\/strong>\uff1a\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(m + n)\uff0c\u5176\u4e2d m \u548c n \u5206\u522b\u662f\u4e24\u4e2a\u8f93\u5165\u987a\u5e8f\u8868\u7684\u957f\u5ea6\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u94fe\u5f0f\u6709\u5e8f\u8868\u7684\u5408\u5e76<\/h3>\n\n\n\n<p>\u5728\u5f00\u59cb\u8bb2\u8fd9\u4e2a\u7b97\u6cd5\u7684\u5177\u4f53\u5b9e\u73b0\u4e4b\u524d\uff0c\u54b1\u5148\u6765\u4e2a\u65bd\u6cd5\u524d\u6447\uff0c\u8bb2\u4e00\u4e0b\u987a\u5e8f\u8868\u548c\u94fe\u8868\u7684\u6709\u5e8f\u8868\u7684\u5408\u5e76\u6709\u4ec0\u4e48\u4e0d\u540c\u3002<\/p>\n\n\n\n<p>\u9996\u5148\uff0c\u5355\u94fe\u8868LA\uff0cLB\u90fd\u662f\u94fe\u5f0f\u5b58\u50a8\u7ed3\u6784\uff0c\u94fe\u8868\u4e4b\u95f4\u7684\u7ed3\u70b9\u90fd\u662f\u901a\u8fc7\u6307\u9488\u6765\u8fde\u63a5\u7684\uff0c\u6240\u4ee5\u5728\u8fdb\u884c\u5408\u5e76\u64cd\u4f5c\u65f6\u4e0d\u9700\u8981\u53e6\u5916\u5f00\u8f9f\u65b0\u7684\u5185\u5b58\u7a7a\u95f4\uff0c\u53ef\u4ee5\u76f4\u63a5\u5229\u7528\u539f\u6765\u4e24\u4e2a\u8868\u7684\u5b58\u50a8\u7a7a\u95f4\uff0c\u5408\u5e76\u7684\u8fc7\u7a0b\u4e2d\u628aLA\uff0cLB\u4e24\u4e2a\u8868\u4e2d\u7684\u7ed3\u70b9\u91cd\u65b0\u8fde\u63a5\u5373\u53ef\u3002<\/p>\n\n\n\n<p>\u7b97\u6cd5\u6b65\u9aa4<\/p>\n\n\n\n<p>\u2460\u6307\u9488pa\u548cpb\u521d\u59cb\u5316\uff0c\u5206\u522b\u6307\u5411LA\u548cLB\u7684\u7b2c\u4e00\u4e2a\u7ed3\u70b9\u3002<\/p>\n\n\n\n<p>\u2461LC\u7684\u7ed3\u70b9\u53d6\u503c\u4e3aLA\u7684\u5934\u7ed3\u70b9\u3002<\/p>\n\n\n\n<p>\u2462\u6307\u9488pc\u521d\u59cb\u5316\uff0c\u6307\u5411LC\u7684\u5934\u7ed3\u70b9\u3002<\/p>\n\n\n\n<p>\u2463\u5f53\u6307\u9488pa\u548cpb\u5747\u672a\u8fbe\u5230\u76f8\u5e94\u7684\u8868\u5c3e\u65f6\uff0c\u5219\u4f9d\u6b21\u6bd4\u8f83pa\u548cpb\u6240\u6307\u5411\u7684\u5143\u7d20\u503c\uff0c\u4eceLA\u6216LB\u4e2d\u6458\u53d6\u5143\u7d20\u503c\u8f83\u5c0f\u7684\u7ed3\u70b9\u63d2\u5165LC\u7684\u6700\u540e\u3002<\/p>\n\n\n\n<p>\u2464\u5c06\u975e\u7a7a\u8868\u7684\u5269\u4f59\u6bb5\u63d2\u5165pc\u6240\u6307\u7ed3\u70b9\u4e4b\u540e\u3002<\/p>\n\n\n\n<p>\u2465\u91ca\u653eLB\u7684\u5934\u7ed3\u70b9\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>void MergeList_L(LinkList&amp; LA, LinkList&amp; LB, LinkList&amp; LC) {\n\t\/\/\u5df2\u77e5\u5355\u94fe\u8868LA\u548cLB\u7684\u5143\u7d20\u6309\u503c\u975e\u9012\u51cf\u6392\u5217\n\t\/\/\u5f52\u5e76LA\u548cLB\u5f97\u5230\u65b0\u7684\u5355\u94fe\u8868LC,LC\u7684\u5143\u7d20\u4e5f\u6309\u503c\u975e\u9012\u51cf\u6392\u5217\n\tLNode* pa;\n\tLNode* pb;\n\tLNode* pc;\n\tpa = LA-&gt;next;  \n\tpb = LB-&gt;next;  \n\tLC = LA;        \/\/\u7528LA\u7684\u5934\u7ed3\u70b9\u4f5c\u4e3aLC\u7684\u5934\u7ed3\u70b9\n\tpc = LC;        \/\/pc\u7684\u521d\u503c\u6307\u5411LC\u7684\u5934\u7ed3\u70b9\n\twhile (pa &amp;&amp; pb) {\n\t\t\/\/LA\u548cLB\u5747\u672a\u5230\u8fbe\u8868\u5c3e\uff0c\u4f9d\u6b21\u201c\u6458\u53d6\u201d\u4e24\u8868\u4e2d\u503c\u8f83\u5c0f\u7684\u7ed3\u70b9\u63d2\u5165\u5230LC\u7684\u6700\u540e\n\t\tif (pa-&gt;elem &lt;= pb-&gt;elem) {  \/\/\u6458\u53d6pa\u7684\u7ed3\u70b9\n\t\t\tpc-&gt;next = pa;   \/\/\u5c06pa\u6240\u6307\u7ed3\u70b9\u94fe\u63a5\u5230pc\u6240\u6307\u7ed3\u70b9\u4e4b\u540e\n\t\t\tpc = pa;         \/\/pc\u6307\u5411pa\n\t\t\tpa = pa-&gt;next;   \/\/pa\u6307\u5411\u4e0b\u4e00\u4e2a\u7ed3\u70b9\n\t\t}\n\t\telse {\/\/\u6458\u53d6pb\u7684\u7ed3\u70b9\n\t\t\tpc-&gt;next = pb;   \/\/\u5c06pb\u6240\u6307\u7ed3\u70b9\u94fe\u63a5\u5230pc\u6240\u6307\u7ed3\u70b9\u4e4b\u540e\n\t\t\tpc = pb;         \/\/pc\u6307\u5411pb\n\t\t\tpb = pb-&gt;next;   \/\/pb\u6307\u5411\u4e0b\u4e00\u8282\u70b9\n\t\t}\n\t}\n\tpc-&gt;next = pa ? pa : pb; \/\/\u5c06\u975e\u7a7a\u8868\u7684\u5269\u4f59\u6bb5\u63d2\u5165\u5230pc\u6240\u6307\u7ed3\u70b9\u4e4b\u540e\n\tdelete LB;               \/\/\u91ca\u653eLB\u7684\u5934\u7ed3\u70b9\n}<\/code><\/pre>\n\n\n\n<p>\u8fd9\u91cc\u9762\u7684pc=pa\u548cpc=pb\u7684\u64cd\u4f5c\u662f\u4e3a\u4e86\u66f4\u65b0\u6307\u9488pc\uff0c\u4f7f\u5176\u6307\u5411\u65b0\u94fe\u8868LC\u4e2d\u6700\u65b0\u6dfb\u52a0\u7684\u7ed3\u70b9\u3002\u76ee\u7684\u662f\u786e\u4fddpc\u59cb\u7ec8\u6307\u5411LC\u7684\u5f53\u524d\u6700\u540e\u4e00\u4e2a\u7ed3\u70b9\uff0c\u4ece\u800c\u80fd\u591f\u5728\u4e0b\u4e00\u6b21\u8fed\u4ee3\u65f6\u6b63\u786e\u7684\u5c06\u4e0b\u4e00\u4e2a\u5143\u7d20\u94fe\u63a5\u5230LC\u7684\u672b\u5c3e\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u7ebf\u6027\u8868\u8868\u793a\u591a\u9879\u5f0f<\/h2>\n\n\n\n<p>\u5148\u8bb2\u4e00\u5143\u591a\u9879\u5f0f\u7684\u4f8b\u5b50\u3002<\/p>\n\n\n\n<p>\u6839\u636e\u4e4b\u524d\u5199\u7684\u8bb2\u7ebf\u6027\u8868\u7684\u6587\u7ae0\uff0c\u53ef\u4ee5\u628a\u4e00\u5143\u591a\u9879\u5f0f\u62bd\u8c61\u6210\u4e00\u4e2a\u7ebf\u6027\u8868\u3002<\/p>\n\n\n\n<p>\u5148\u7b80\u5355\u7684\u6765\u8bf4\uff0c\u5bf9\u4e8e\u4e00\u4e2a\u4e00\u5143\u591a\u9879\u5f0f\u6765\u8bf4\uff0c\u5b83\u6700\u4e3b\u8981\u662f\u7531\u7cfb\u6570\u548c\u6307\u6570\u7ec4\u6210\u7684\uff0c\u6211\u4eec\u53ef\u4ee5\u628a\u8fd9\u4e24\u4e2a\u503c\u7531\u4e00\u4e2a\u6570\u7ec4\u6765\u8868\u793a\uff0c\u6570\u7ec4\u7684\u4e0b\u68070\uff0c1\uff0c2......\u6765\u8868\u793a\u6307\u6570\uff0c\u7cfb\u6570\u5c31\u662f\u6570\u7ec4\u91cc\u9762\u5b58\u50a8\u7684\u5143\u7d20\u3002<\/p>\n\n\n\n<p>\u4f8b\u5982\u591a\u9879\u5f0f1+2x+3x<sup>2<\/sup>-5x<sup>3<\/sup>\u53ef\u4ee5\u7528\u6570\u7ec4\u8868\u793a\u4e3a\uff1a<\/p>\n\n\n\n<p>\u56fe\u7247\u5f85\u8865\u5145<\/p>\n\n\n\n<p>\u7528\u8fd9\u4e2a\u73a9\u610f\u8fdb\u884c\u591a\u9879\u5f0f\u76f8\u52a0\u7684\u7b97\u6cd5\u5c31\u5f88\u5bb9\u6613\u5b9e\u73b0\uff0c\u53ea\u9700\u8981\u628a\u4e24\u4e2a\u6570\u7ec4\u76f8\u5e94\u7684\u5206\u91cf\u9879\u76f8\u52a0\u5c31\u53ef\u4ee5\u4e86\u3002<\/p>\n\n\n\n<p>\u63a5\u4e0b\u6765\u5c31\u662f\u7a00\u758f\u591a\u9879\u5f0f\u4e86\uff0c\u5bf9\u4e8e\u7a00\u758f\u591a\u9879\u5f0f\uff0c\u4e5f\u80fd\u62bd\u8c61\u6210\u7ebf\u6027\u8868\uff0c\u7ed3\u5408\u7740\u524d\u6587\u8bb2\u7684\u5f52\u5e76\u7684\u64cd\u4f5c\uff0c\u53ef\u4ee5\u770b\u51fa\uff0c\u7a00\u758f\u591a\u9879\u5f0f\u7684\u76f8\u52a0\u548c\u4e24\u4e2a\u6709\u5e8f\u8868\u7684\u5f52\u5e76\u6781\u5176\u76f8\u4f3c\uff0c\u4e0d\u540c\u4e4b\u5904\u4ec5\u5728\u4e8e\u6709\u5e8f\u8868\u7684\u5f52\u5e76\u53ea\u4f1a\u51fa\u73b0\u5c0f\u4e8e\u7b49\u4e8e\u548c\u5927\u4e8e\u8fd9\u4e24\u79cd\u60c5\u51b5\uff0c\u800c\u7a00\u758f\u591a\u9879\u5f0f\u5728\u76f8\u52a0\u7684\u65f6\u5019\u8981\u8003\u8651\u5927\u4e8e\u3001\u5c0f\u4e8e\u548c\u7b49\u4e8e\u8fd9\u4e09\u79cd\u60c5\u51b5\u3002<\/p>\n\n\n\n<p>\u8fd9\u7bc7\u6587\u7ae0\u5148\u8bb2\u5355\u94fe\u8868\u7684\u8868\u793a\u7a00\u758f\u591a\u9879\u5f0f\uff0c\u8fd9\u4e5f\u662f\u6700\u5e38\u7528\u7684\u65b9\u6cd5\u3002<\/p>\n\n\n\n<p>\u9996\u5148\u8fd8\u662f\u5148\u5b9a\u4e49\u4e00\u4e0b\u591a\u9879\u5f0f\u7684\u6570\u636e\u7ed3\u6784\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>typedef struct PNode {\n\tfloat cof;   \/\/\u7cfb\u6570\n\tint exp;     \/\/\u6307\u6570\n\tstruct PNode *next;\n}PNode,*Poly;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u591a\u9879\u5f0f\u7684\u521b\u5efa<\/h3>\n\n\n\n<p>\u8fd9\u4e2a\u591a\u9879\u5f0f\u7684\u521b\u5efa\u548c\u5355\u94fe\u8868\u7684\u521b\u5efa\u6781\u5176\u76f8\u4f3c\uff0c\u524d\u8005\u5c31\u6bd4\u540e\u8005\u591a\u4e86\u4e00\u4e2a\u6bd4\u5927\u5c0f\u3002<\/p>\n\n\n\n<p>\u7b97\u6cd5\u6b65\u9aa4\uff1a<\/p>\n\n\n\n<p>\u2460\u521b\u5efa\u4e00\u4e2a\u53ea\u6709\u5934\u7ed3\u70b9\u7684\u7a7a\u94fe\u8868\u3002<\/p>\n\n\n\n<p>\u2461\u6839\u636e\u8f93\u5165\u7684\u591a\u9879\u5f0f\u7cfb\u6570n\uff0c\u91cd\u590d\u6267\u884c\u4ee5\u4e0b\u64cd\u4f5c\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u751f\u6210\u4e00\u4e2a\u65b0\u7ed3\u70b9*s\uff1b<\/li>\n\n\n\n<li>\u8f93\u5165\u591a\u9879\u5f0f\u5f53\u524d\u9879\u7684\u7cfb\u6570\u548c\u6307\u6570\u8d4b\u7ed9\u65b0\u7ed3\u70b9*s\u7684\u6570\u636e\u57df\uff1b<\/li>\n\n\n\n<li>\u8bbe\u7f6e\u4e00\u4e2a\u524d\u9a71\u6307\u9488pre\uff0c\u7528\u4e8e\u6307\u5411\u5f85\u627e\u5230\u7684\u7b2c\u4e00\u4e2a\u5927\u4e8e\u8f93\u5165\u9879\u6307\u6570\u7684\u7ed3\u70b9\u7684\u524d\u9a71\uff0cpre\u521d\u59cb\u5316\u65f6\u6307\u5411\u5934\u7ed3\u70b9\uff1b<\/li>\n\n\n\n<li>\u6307\u9488q\u521d\u59cb\u5316\uff0c\u6307\u5411\u9996\u5143\u7ed3\u70b9\uff1b<\/li>\n\n\n\n<li>\u5faa\u73af\u5411\u4e0b\u9010\u4e2a\u6bd4\u8f83\u94fe\u8868\u5f53\u4e2d\u5f53\u524d\u7ed3\u70b9\u7684\u6307\u6570\u4e0e\u8f93\u5165\u9879\u7684\u6307\u6570\uff0c\u627e\u5230\u7b2c\u4e00\u4e2a\u5927\u4e8e\u8f93\u5165\u9879\u6307\u6570\u7684\u7ed3\u70b9*q\uff1b<\/li>\n\n\n\n<li>\u5c06\u8f93\u5165\u9879\u7ed3\u70b9*s\u63d2\u5165\u7ed3\u70b9*q\u4e4b\u524d\u3002<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>void CreatePolyn(Poly&amp; p, int n) {\n\tp=new PNode;\n\tp-&gt;next = NULL;\n\tPNode* s;\n\tcout &lt;&lt; \"\u8bf7\u8f93\u5165\u591a\u9879\u5f0f\u7cfb\u6570\u548c\u6307\u6570\uff1a\" &lt;&lt; endl;\n\tfor (int i = 0; i &lt; n; i++) {\n\t\ts = new PNode;\n\t\tcin &gt;&gt; s-&gt;cof;\n\t\tcin &gt;&gt; s-&gt;exp;\n\t\tPNode *pre = p;\n\t\tPNode *q = p-&gt;next;\n\t\twhile (q &amp;&amp; q-&gt;exp &lt; s-&gt;exp){\n\t\t\tpre = q;\n\t\t\tq = q-&gt;next;\n\t\t}\n\t\ts-&gt;next = q;\n\t\tpre-&gt;next = s;\n\t}\n}<\/code><\/pre>\n\n\n\n<p>\u91cc\u9762\u7684pre\u6307\u9488\u548cq\u6307\u9488\u90fd\u662f\u4e3a\u4e86\u5c06\u65b0\u521b\u5efa\u7684s\u7ed3\u70b9\u51c6\u786e\u7684\u63d2\u5165\u6b63\u786e\u7684\u4f4d\u7f6e\u3002<\/p>\n\n\n\n<p>\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u5728\u8fd9\u6bb5\u4ee3\u7801\u4e2d\uff0c<code>p<\/code> \u88ab\u521d\u59cb\u5316\u4e3a\u4e00\u4e2a\u65b0\u7684 PNode\uff0c\u4f46\u8fd9\u4e2a\u8282\u70b9\u5e76\u6ca1\u6709\u88ab\u7528\u4f5c\u5b9e\u9645\u7684\u6570\u636e\u8282\u70b9\u3002\u56e0\u6b64\uff0c\u5b9e\u9645\u7684\u591a\u9879\u5f0f\u6570\u636e\u662f\u4ece <code>p-&gt;next<\/code> \u5f00\u59cb\u7684\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u591a\u9879\u5f0f\u7684\u76f8\u52a0<\/h2>\n\n\n\n<p>\u591a\u9879\u5f0f\u7684\u76f8\u52a0\u76f8\u5f53\u4e8e\u662f\u6709\u5e8f\u8868\u7684\u5f52\u5e76\uff0c\u53ea\u662f\u7ec6\u8282\u4e0a\u6709\u4e9b\u4e0d\u592a\u76f8\u540c\u3002\u8fd9\u91cc\u4e0d\u518d\u8fc7\u591a\u89e3\u91ca\uff0c\u76f4\u63a5\u7ed9\u51fa\u7b97\u6cd5\u6b65\u9aa4<\/p>\n\n\n\n<p>\u7b97\u6cd5\u6b65\u9aa4\uff1a<\/p>\n\n\n\n<p>\u2460\u521d\u59cb\u5316\uff1a<\/p>\n\n\n\n<p><code>p1<\/code>&nbsp;\u6307\u5411&nbsp;<code>p<\/code>&nbsp;\u94fe\u8868\u7684\u7b2c\u4e00\u4e2a\u5b9e\u9645\u6570\u636e\u8282\u70b9\uff08\u5373&nbsp;<code>p-&gt;next<\/code>\uff09\u3002<\/p>\n\n\n\n<p><code>p2<\/code>&nbsp;\u6307\u5411&nbsp;<code>q<\/code>&nbsp;\u94fe\u8868\u7684\u7b2c\u4e00\u4e2a\u5b9e\u9645\u6570\u636e\u8282\u70b9\uff08\u5373&nbsp;<code>q-&gt;next<\/code>\uff09\u3002<\/p>\n\n\n\n<p><code>pre<\/code>&nbsp;\u7528\u4e8e\u8ddf\u8e2a\u7ed3\u679c\u94fe\u8868\u4e2d\u7684\u6700\u540e\u4e00\u4e2a\u8282\u70b9\uff0c\u521d\u59cb\u65f6\u6307\u5411&nbsp;<code>p<\/code>&nbsp;\u7684\u54d1\u7ed3\u70b9\u3002<\/p>\n\n\n\n<p><code>sum<\/code>&nbsp;\u7528\u6765\u6682\u5b58\u4e24\u4e2a\u76f8\u540c\u6307\u6570\u9879\u7cfb\u6570\u76f8\u52a0\u7684\u7ed3\u679c\u3002<\/p>\n\n\n\n<p><code>s<\/code>&nbsp;\u7528\u4f5c\u4e34\u65f6\u6307\u9488\uff0c\u4e3b\u8981\u7528\u4e8e\u5220\u9664\u591a\u4f59\u7684\u8282\u70b9\u3002<\/p>\n\n\n\n<p>\u2461\u904d\u5386\u548c\u5408\u5e76\uff1a<\/p>\n\n\n\n<p>\u4f7f\u7528&nbsp;<code>while (p1 &amp;&amp; p2)<\/code>&nbsp;\u5faa\u73af\u6765\u5904\u7406&nbsp;<code>p1<\/code>&nbsp;\u548c&nbsp;<code>p2<\/code>&nbsp;\u90fd\u975e\u7a7a\u7684\u60c5\u51b5\u3002<\/p>\n\n\n\n<p>\u5728\u5faa\u73af\u4e2d\uff0c\u6bd4\u8f83&nbsp;<code>p1<\/code>&nbsp;\u548c&nbsp;<code>p2<\/code>&nbsp;\u5f53\u524d\u8282\u70b9\u7684\u6307\u6570 (<code>exp<\/code>)\uff1a<\/p>\n\n\n\n<p>\u5982\u679c&nbsp;<code>p1-&gt;exp == p2-&gt;exp<\/code>\uff0c\u5219\u8bf4\u660e\u8fd9\u4e24\u4e2a\u8282\u70b9\u6709\u76f8\u540c\u7684\u6307\u6570\uff0c\u5b83\u4eec\u7684\u7cfb\u6570\u5e94\u8be5\u76f8\u52a0\u3002\u5982\u679c\u76f8\u52a0\u540e\u7684\u7cfb\u6570&nbsp;<code>sum<\/code>&nbsp;\u4e0d\u4e3a0\uff0c\u5219\u66f4\u65b0&nbsp;<code>p1<\/code>&nbsp;\u7684\u7cfb\u6570\u4e3a&nbsp;<code>sum<\/code>&nbsp;\u5e76\u5c06&nbsp;<code>p1<\/code>&nbsp;\u8282\u70b9\u94fe\u63a5\u5230\u7ed3\u679c\u94fe\u8868\u4e2d\uff1b\u5426\u5219\uff0c\u5220\u9664\u8fd9\u4e24\u4e2a\u8282\u70b9\u3002<\/p>\n\n\n\n<p>\u5982\u679c&nbsp;<code>p1-&gt;exp &lt; p2-&gt;exp<\/code>\uff0c\u5219&nbsp;<code>p1<\/code>&nbsp;\u8282\u70b9\u5e94\u5148\u52a0\u5165\u7ed3\u679c\u94fe\u8868\uff0c\u56e0\u4e3a\u5b83\u7684\u6307\u6570\u8f83\u5c0f\u3002<\/p>\n\n\n\n<p>\u5982\u679c&nbsp;<code>p1-&gt;exp &gt; p2-&gt;exp<\/code>\uff0c\u5219&nbsp;<code>p2<\/code>&nbsp;\u8282\u70b9\u5e94\u5148\u52a0\u5165\u7ed3\u679c\u94fe\u8868\uff0c\u56e0\u4e3a\u5b83\u7684\u6307\u6570\u8f83\u5c0f\u3002<\/p>\n\n\n\n<p>\u2462\u5904\u7406\u5269\u4f59\u8282\u70b9\uff1a<\/p>\n\n\n\n<p>\u5f53\u4e00\u4e2a\u94fe\u8868\u904d\u5386\u5b8c\u6bd5\u540e\uff08\u5373&nbsp;<code>p1<\/code>&nbsp;\u6216&nbsp;<code>p2<\/code>&nbsp;\u53d8\u4e3a\u7a7a\uff09\uff0c\u53e6\u4e00\u4e2a\u94fe\u8868\u53ef\u80fd\u8fd8\u6709\u5269\u4f59\u7684\u8282\u70b9\u672a\u88ab\u5904\u7406\u3002\u8fd9\u65f6\uff0c\u5c06\u5269\u4f59\u7684\u6574\u4e2a\u94fe\u8868\u76f4\u63a5\u8fde\u63a5\u5230\u7ed3\u679c\u94fe\u8868\u7684\u672b\u5c3e\u3002<\/p>\n\n\n\n<p>\u8fd9\u662f\u901a\u8fc7&nbsp;<code>pre-&gt;next = p1 ? p1 : p2;<\/code>&nbsp;\u5b8c\u6210\u7684\uff0c\u8fd9\u91cc\u4f7f\u7528\u4e86\u4e09\u5143\u8fd0\u7b97\u7b26\u6765\u9009\u62e9\u975e\u7a7a\u7684\u94fe\u8868\u3002<\/p>\n\n\n\n<p>\u2463\u6e05\u7406\uff1a<\/p>\n\n\n\n<p>\u6700\u540e\uff0c\u5220\u9664&nbsp;<code>q<\/code>&nbsp;\u7684\u54d1\u7ed3\u70b9\uff0c\u56e0\u4e3a\u5b83\u4e0d\u518d\u9700\u8981\u3002\u6ce8\u610f\u8fd9\u91cc\u5220\u9664\u7684\u662f&nbsp;<code>q<\/code>&nbsp;\u7684\u54d1\u7ed3\u70b9\uff0c\u800c\u4e0d\u662f\u6574\u4e2a&nbsp;<code>q<\/code>&nbsp;\u94fe\u8868\uff0c\u56e0\u4e3a\u5728\u524d\u9762\u7684\u64cd\u4f5c\u4e2d\uff0c<code>q<\/code>&nbsp;\u94fe\u8868\u4e2d\u7684\u6709\u6548\u8282\u70b9\u5df2\u7ecf\u88ab\u79fb\u52a8\u5230\u4e86&nbsp;<code>p<\/code>&nbsp;\u4e2d\u6216\u88ab\u5220\u9664\u3002<\/p>\n\n\n\n<p>\u2464\u7ed3\u675f\uff1a<\/p>\n\n\n\n<p>\u51fd\u6570\u6267\u884c\u5b8c\u6bd5\u540e\uff0c<code>p<\/code>&nbsp;\u94fe\u8868\u5305\u542b\u4e86\u4e24\u4e2a\u591a\u9879\u5f0f\u76f8\u52a0\u540e\u7684\u7ed3\u679c\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>void AddPoly(Poly&amp; p, Poly&amp; q) {\n\tPNode* p1 = p-&gt;next;\n\tPNode* p2 = q-&gt;next;\n\tPNode* pre = p;\n\tint sum;\n\tPNode* s;\n\twhile (p1 &amp;&amp; p2) {\n\t\tif (p1-&gt;exp == p2-&gt;exp) {\n\t\t\tsum = p1-&gt;cof + p2-&gt;cof;\n\t\t\tif (sum != 0) {\n\t\t\t\tp1-&gt;cof = sum;\n\t\t\t\tpre-&gt;next = p1;\n\t\t\t\tpre = p1;\n\t\t\t\tp1 = p1-&gt;next;\n\t\t\t\ts = p2;\n\t\t\t\tp2 = p2-&gt;next;\n\t\t\t\tdelete s;\n\t\t\t}\n\t\t\telse {\n\t\t\t\ts = p1;\n\t\t\t\tp1 = p1-&gt;next;\n\t\t\t\tdelete s;\n\t\t\t\ts = p2;\n\t\t\t\tp2 = p2-&gt;next;\n\t\t\t\tdelete s;\n\t\t\t}\n\t\t}\n\t\telse if (p1-&gt;exp &lt; p2-&gt;exp) {\n\t\t\tpre-&gt;next = p1;\n\t\t\tpre = p1;\n\t\t\tp1 = p1-&gt;next;\n\t\t}\n\t\telse{\n\t\t\tpre-&gt;next = p2;\n\t\t\tpre = p2;\n\t\t\tp2 = p2-&gt;next;\n\t\t}\n\t}\n\tpre-&gt;next = p1 ? p1 : p2;\n\tdelete q;\n\t}\nvoid PrintPoly(Poly p) {\n\tPNode* q = p-&gt;next;\n\twhile (q) {\n\t\tcout &lt;&lt; q-&gt;cof &lt;&lt; \" \" &lt;&lt; q-&gt;exp;\n\t\tq = q-&gt;next;\n\t\tif (q) {\n\t\t\tcout &lt;&lt; \" \";\n\t\t}\n\t}\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u5199\u5728\u6700\u540e<\/h2>\n\n\n\n<p>\u4ee5\u4e0a\u5c31\u662f\u7ebf\u6027\u8868\u7684\u5e94\u7528\uff08\u867d\u8bf4\u53ea\u662f\u7b80\u5355\u4e3e\u4e86\u51e0\u4e2a\u4f8b\u5b50\uff09\u3002\u7b49\u6709\u7a7a\u7684\u65f6\u5019\u518d\u5b8c\u5584\u4e00\u4e0b2024\/10\/18\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u524d\u8a00 \u8fd9\u7bc7\u7b97\u662f\u5bf9\u7ebf\u6027\u8868\u7684\u7b97\u6cd5\u7684\u8865\u5145\uff0c\u5b66\u5b8c\u524d\u4e24\u7bc7\u4e4b\u540e\u624d\u53ef\u4ee5\u770b\u8fd9\u4e00\u7bc7\u3002\u5176\u4e2d\u6709\u51e0\u4e2a\u64cd\u4f5c\u524d\u51e0\u7bc7\u6587\u7ae0\u63d0\u5230\u8fc7\uff0c\u4f46\u662f\u8fd9\u91cc\u8fd8\u662f\u8981\u5728\u63d0\u4e00\u6b21\u3002 \u7ebf\u6027\u8868 &#8230;<\/p>\n","protected":false},"author":1,"featured_media":235,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-202","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.xxinran.tech\/index.php\/wp-json\/wp\/v2\/posts\/202"}],"collection":[{"href":"https:\/\/www.xxinran.tech\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xxinran.tech\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xxinran.tech\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xxinran.tech\/index.php\/wp-json\/wp\/v2\/comments?post=202"}],"version-history":[{"count":9,"href":"https:\/\/www.xxinran.tech\/index.php\/wp-json\/wp\/v2\/posts\/202\/revisions"}],"predecessor-version":[{"id":250,"href":"https:\/\/www.xxinran.tech\/index.php\/wp-json\/wp\/v2\/posts\/202\/revisions\/250"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.xxinran.tech\/index.php\/wp-json\/wp\/v2\/media\/235"}],"wp:attachment":[{"href":"https:\/\/www.xxinran.tech\/index.php\/wp-json\/wp\/v2\/media?parent=202"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xxinran.tech\/index.php\/wp-json\/wp\/v2\/categories?post=202"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xxinran.tech\/index.php\/wp-json\/wp\/v2\/tags?post=202"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}