{"id":388,"date":"2019-12-21T14:59:23","date_gmt":"2019-12-21T06:59:23","guid":{"rendered":"http:\/\/www.guanhaobo.cn\/?p=388"},"modified":"2019-12-21T14:59:23","modified_gmt":"2019-12-21T06:59:23","slug":"pat-advanced-level-practice-1002-ab-for-polynomials","status":"publish","type":"post","link":"https:\/\/www.guanhaobo.cn\/?p=388","title":{"rendered":"PAT (Advanced Level) Practice 1002 A+B for Polynomials"},"content":{"rendered":"<p>This time, you are supposed to find A+B 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: K N1 aN1 N2 aN2 &#8230; NK aNK, where K is the number of nonzero terms in the polynomial, Ni and aNi (i=1, 2, &#8230;, K) are the exponents and coefficients, respectively. It is given that 1 &lt;= K &lt;= 10\uff0c0 &lt;= NK &lt; &#8230; &lt; N2 &lt; N1 &lt;=1000.<\/p>\n<h3>Output Specification:<\/h3>\n<p>For each test case you should output the sum 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 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 2 1.5 1 2.9 0 3.2\n<\/code><\/pre>\n<h3>\u9898\u76ee\u5927\u610f<\/h3>\n<p>\u4e24\u4e2a\u591a\u9879\u5f0f\u6c42\u548c\uff0c\u6bcf\u4e00\u884c\u8868\u793a\u4e00\u4e2a\u591a\u9879\u5f0f\u3002<br \/>\n\u6bcf\u4e00\u884c\u7b2c\u4e00\u4e2a\u6570K\u8868\u793a\u6709K\u4e2a\u975e0\u7684\u9879\uff0c\u6bcf\u4e00\u9879\u6709\u6307\u6570 N \u548c\u7cfb\u6570 a<br \/>\n\u5c06\u7ed3\u679c\u6309\u7167\u548c\u8f93\u5165\u76f8\u540c\u7684\u683c\u5f0f\u8fdb\u884c\u8f93\u51fa\uff0c\u7cfb\u6570\u7cbe\u786e\u5230\u5c0f\u6570\u70b9\u540e\u4e00\u4f4d\u3002<\/p>\n<h3>\u9898\u76ee\u5206\u6790<\/h3>\n<p>\u5f00\u4e2a\u6570\u7ec4sum[1005]\uff0c\u5176\u4e2dsum[i]\u8868\u793a\u6307\u6570\u4e3a i \u7684\u9879\u7684\u7cfb\u6570\u548c\u3002<br \/>\n\u6700\u540e\u904d\u5386sum\u6570\u7ec4\uff0c\u627e\u51fa\u975e0\u9879\u7684\u4e2a\u6570\uff0c\u7136\u540e\u8f93\u51fa\u7ed3\u679c\u5373\u53ef\uff0c\u8981\u6309\u7167\u6307\u6570\u4ece\u9ad8\u5230\u4f4e\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;\ndouble sum[1005] = {0};\nint main()\n{\n    int k, i, x, cnt = 0;\n    double y;\n    for (i = 0; i &lt; 2; i++) \/\/2\u884c\n    {\n        cin &gt;&gt; k;\n        while (k--)\n        {\n            cin &gt;&gt; x &gt;&gt; y;\n            sum[x] += y;\n        }\n    }\n    for (i = 0; i &lt; 1005; i++)\n        if (sum[i])\n            cnt++;\n    cout &lt;&lt; cnt;\n    for (i = 1004; i &gt;= 0; i--)\n        if (sum[i])\n            printf(\" %d %.1f\", i, sum[i]);\n    return 0;\n}\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>This time, you are supposed to find A+B 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-388","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\/388","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=388"}],"version-history":[{"count":0,"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=\/wp\/v2\/posts\/388\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=388"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=388"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=388"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}