1009 Product of polynomials

Source: Internet
Author: User

Title Link: https://pintia.cn/problem-sets/994805342720868352/problems/994805509540921344

Polynomial multiplication, here is the code:

1 //Note the format of the output2#include <iostream>3#include <queue>4#include <iomanip>5 using namespacestd;6 structpol{7     floatXishu;8     intZhishu;9FriendBOOL operator<(Pol X,pol y) {Ten         returnX.zhishu <Y.zhishu; One     } AFriendvoid operator* (Pol &x,pol &Other ) { -X.xishu *=Other.xishu; -X.zhishu + =Other.zhishu; the     } -Friendvoid operator+ (Pol &x,pol &Other ) { -X.xishu + =Other.xishu; -     } + }; -  + intMain () { APriority_queue<pol>Q1; atPriority_queue<pol>Q2; -Priority_queue<pol>Q3; -Priority_queue<pol>Q4; - pol P; -     intn,m; -CIN >>N; in      for(inti =0; I < n; i++){ -CIN >> P.zhishu >>P.xishu; to Q1.push (p); +     } -CIN >>m; the      for(inti =0; I < m; i++){ *CIN >> P.zhishu >>P.xishu; $ Q2.push (p);Panax Notoginseng     } -     //q3 = Q2; the     intN1 =q1.size (); +     intN2 =q2.size (); A      for(inti =0; I < N1; i++){ thePol P1 =q1.top (); +  - Q1.pop (); $          for(intj =0; J < N2; J + +){ $p =P1; -Pol P2 =q2.top (); - //cout << P2.zhishu << "<< P2.xishu << Endl; the Q2.pop (); - Q3.push (p2);Wuyip*P2; the //cout << P.zhishu << "<< P.xishu << Endl; - Q4.push (p); Wu         } -          while(!Q3.empty ()) { About Q2.push (Q3.top ()); $ Q3.pop (); -         } -     } - //for (int i = 0; i < q4.size (); i++) { A ////cout<< q4.top (). Zhishu << "" << q4.top (). Xishu << Endl; + //Q4.pop (); the //    } -p =q4.top (); $N1 =q4.size (); the Q4.pop (); the      for(inti =0; I < n1-1; i++){ thePol P1 =q4.top (); the Q4.pop (); -         if(P.zhishu = =P1.zhishu) { in //cout << P.zhishu << "<< P1.zhishu << Endl; thep+P1; the //cout << P.zhishu << "<< P.xishu << Endl; About  the         } the         Else{ the             if(P.xishu! =0) + Q3.push (p); -p =P1; the //cout << P.zhishu << "<< P.xishu << Endl;Bayi         } the     } the     if(P.xishu! =0) Q3.push (p); -     //Q3.push (p); -cout << q3.size () <<" "; theN1 =q3.size (); the      for(inti =0; I < N1; i++){ the         if(I! = n1-1){ thecout << q3.top (). Zhishu <<" "<<fixed<< Setprecision (1) << Q3.top (). Xishu <<" "; - Q3.pop (); the         } the         Elsecout << q3.top (). Zhishu <<" "<<fixed<< Setprecision (1) <<q3.top (). Xishu; the     }94 //cout << P.zhishu << "<< P.xishu; the //cout << q3.size () << Endl; the //cout << q3.top (). Zhishu << << q3.top (). Xishu; the     return 0;98}

1009 Product of polynomials

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.