{"id":474,"date":"2020-01-12T16:08:55","date_gmt":"2020-01-12T08:08:55","guid":{"rendered":"http:\/\/www.guanhaobo.cn\/?p=474"},"modified":"2020-01-12T16:08:55","modified_gmt":"2020-01-12T08:08:55","slug":"pat-advanced-level-practice-1009-product-of-polynomials","status":"publish","type":"post","link":"https:\/\/www.guanhaobo.cn\/?p=474","title":{"rendered":"PAT (Advanced Level) Practice 1009 Product of Polynomials"},"content":{"rendered":"<p>This time, you are supposed to find A\u00d7B where A and B are two polynomials.<\/p>\n<h3>Input Specification:<\/h3>\n<p>Each input file contains one test case. Each case occupies 2 lines, and each line contains the information of a polynomial:<br \/>\n<code>K N1 aN1 N2 aN2 ... NK aNK<\/code><br \/>\nwhere K is the number of nonzero terms in the polynomial, Ni and aNi (i=1,2,\u22ef,K) are the exponents and coefficients, respectively. It is given that 1\u2264K\u226410, 0\u2264NK&lt;\u22ef&lt;N2&lt;N1\u22641000.<\/p>\n<h3>Output Specification:<\/h3>\n<p>For each test case you should output the product of A and B in one line, with the same format as the input. Notice that there must be NO extra space at the end of each line. Please be accurate up to 1 decimal place.<\/p>\n<h3>Sample Input:<\/h3>\n<pre><code class=\"language-cpp line-numbers\">2 1 2.4 0 3.2\n2 2 1.5 1 0.5\n<\/code><\/pre>\n<h3>Sample Output:<\/h3>\n<pre><code class=\"language-cpp line-numbers\">3 3 3.6 2 6.0 1 1.6\n<\/code><\/pre>\n<h3>\u9898\u76ee\u5927\u610f<\/h3>\n<p>\u7ed9\u51fa\u4e24\u4e2a\u591a\u9879\u5f0f\uff0c\u6c42\u591a\u9879\u5f0f\u7684\u4e58\u79ef\u3002<\/p>\n<h3>\u9898\u76ee\u5206\u6790<\/h3>\n<p>NK\u6700\u5927\u662f1000\uff0c\u6240\u4ee5\u4e58\u79ef\u4e2d\u6307\u6570\u6700\u5927\u4e3a2000.<br \/>\n\u5f00\u4e00\u4e2a\u6570\u7ec4ans[2005]\uff0cans[x]\u8868\u793a\u6307\u6570\u4e3ax\u7684\u9879\u7684\u7cfb\u6570\u3002<br \/>\n\u4e24\u5c42\u5faa\u73af\uff0c\u7ef4\u62a4ans\u6570\u7ec4\u5373\u53ef\u3002\u6700\u540e\u5c06ans\u4e2d\u7684\u975e\u96f6\u9879\u6309\u7167\u8981\u6c42\u7684\u683c\u5f0f\u8fdb\u884c\u8f93\u51fa\u3002<\/p>\n<h3>AC\u4ee3\u7801<\/h3>\n<pre><code class=\"language-cpp line-numbers\">#include &lt;bits\/stdc++.h&gt;\nusing namespace std;\nstruct node\n{\n    int n;\n    double v;\n} a[2][10];\ndouble ans[2005] = {0};\nint main()\n{\n    int i, j, k, cnt = 0;\n    for (i = 0; i &lt; 2; i++)\n    {\n        cin &gt;&gt; k;\n        for (j = 0; j &lt; k; j++)\n            cin &gt;&gt; a[i][j].n &gt;&gt; a[i][j].v;\n    }\n    for (i = 0; i &lt; 10; i++)\n        for (j = 0; j &lt; 10; j++)\n            ans[a[0][i].n + a[1][j].n] += a[0][i].v * a[1][j].v;\n    for (i = 0; i &lt;= 2000; i++)\n    {\n        if (ans[i])\n            cnt++;\n    }\n    cout &lt;&lt; cnt;\n    for (i = 2000; i &gt;= 0; i--)\n    {\n        if (ans[i])\n            printf(\" %d %.1f\", i, ans[i]);\n    }\n    return 0;\n}\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>This time, you are supposed to find A\u00d7B where A and B a [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[23,54],"class_list":["post-474","post","type-post","status-publish","format-standard","hentry","category-algo","tag-pat","tag-54"],"_links":{"self":[{"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=\/wp\/v2\/posts\/474","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=474"}],"version-history":[{"count":0,"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=\/wp\/v2\/posts\/474\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=474"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=474"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=474"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}