Analysis of Pat computer questions from Zhejiang University 1009. Product of polynomials (25)

Source: Internet
Author: User
1009. Product of polynomials (25) Time Limit 400 MS
The memory limit is 32000 kb.
Code length limit: 16000 B
Criterion author Chen, Yue

This time, you are supposed to find a * B where A and B are two polynomials.

Input specification:

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... NK ank, where k is the number of nonzero terms in
The polynomial, Ni and Ani (I = 1, 2 ,..., k) are the exponents and coefficients, respectively. it is given that 1 <= k <= 10, 0 <= NK <... <N1 <= 1000.

Output specification:

For each test case you shoshould 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.

Sample Input

2 1 2.4 0 3.22 2 1.5 1 0.5

Sample output

3 3 3.6 2 6.0 1 1.6
 
# Include <iostream> # include <vector> # include <algorithm> # include <iomanip> using namespace STD; typedef struct node {int exp; // index float COE; // coefficient} node; node product (node A, Node B) {. exp =. exp + B. exp;. COE =. COE * B. COE; return a;} bool compare (node A, Node B) {return. exp> B. exp;} int main () {node; int M, N; vector <node> vec1, vec2, VEC, vec3; vector <node >:: iterator it1, it2; cin> m; while (M --) {CIN> Node. exp> node. COE; vec1.push _ back (node);} CIN> N; while (n --) {CIN> node. exp> node. COE; vec2.push _ back (node);} For (it1 = vec1.begin (); it1! = Vec1.end (); it1 ++) for (it2 = vec2.begin (); it2! = Vec2.end (); it2 ++) {node T = product (* it1, * it2); If (T. COE! = 0) Vec. push_back (t);} Sort (VEC. Begin (), VEC. End (), compare); For (it1 = Vec. Begin (); it1! = Vec. End (); it1 = it2) {for (it2 = it1 + 1; it2! = Vec. end () & (* it1 ). exp = (* it2 ). exp); it2 ++) (* it1 ). COE + = (* it2 ). COE; If (* it1 ). COE! = 0) {vec3.push _ back (* it1) ;}} cout <vec3.size (); For (it1 = vec3.begin (); it1! = Vec3.end (); it1 ++) cout <"" <(* it1 ). exp <"" <fixed <setprecision (1) <(* it1 ). COE; cout <Endl; // system ("pause"); Return 0 ;}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.