1009 Product of Polynomials (25)(25 point(s))

problem

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 a~N1~ N2 a~N2~ ... NK a~NK~, where K is the number of nonzero terms in the polynomial, Ni and a~Ni~ (i=1, 2, ..., K) are the exponents and coefficients, respectively. It is given that 1 <= K <= 10, 0 <= NK < ... < N2 < N1 <=1000.

Output Specification:

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.

Sample Input

2 1 2.4 0 3.2
2 2 1.5 1 0.5
Sample Output

3 3 3.6 2 6.0 1 1.6

tip

求多项式的乘积。

answer

#include<bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
#define Max 1000005

int N, M;
float num[Max];
pair<int ,float> n1[Max], n2[Max];

int main(){
//  freopen("test.txt", "r", stdin);
    memset(num, 0, sizeof(num));
    memset(n1, 0, sizeof(n1));
    memset(n2, 0, sizeof(n2));

    cin>>N;
    for(int i = 0; i < N; i++) {
        cin>>n1[i].first>>n1[i].second;
    }
    cin>>M;
    for(int i = 0; i < M; i++) {
        cin>>n2[i].first>>n2[i].second;
    }
    int number = 0;
    for(int i = 0; i < N; i++){
        for(int j = 0; j < M; j++){
            int ex = n1[i].first + n2[j].first;
            float co = n1[i].second * n2[j].second;
            num[ex] += co;
        }
    }
    for(int i = 0; i < Max; i++) if(num[i] != 0) number ++;
    cout<<number;
    for(int i = Max -1; i >= 0; i--){
        if(num[i] != 0){
            cout<<" "<<i<<" ";
            cout<<fixed<<setprecision(1)<<num[i];
        }
    }

    return 0;
}

experience

  • 注意数组越界问题。
  • 读清楚题意,多设计一组测试用例。

原文地址:https://www.cnblogs.com/yoyo-sincerely/p/9270837.html

时间: 2024-11-03 16:46:03

1009 Product of Polynomials (25)(25 point(s))的相关文章

1009 Product of Polynomials (25)(25 分)

1009 Product of Polynomials (25)(25 分) 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 pol

PAT 1009. Product of Polynomials (25)

1009. Product of Polynomials (25) 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 polynomi

1009. Product of Polynomials (25)——PAT (Advanced Level) Practise

题目信息: 1009. Product of Polynomials (25) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 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 c

1009 Product of Polynomials (25分) 多项式乘法

1009 Product of Polynomials (25分) 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 polynomi

[PTA] PAT(A) 1009 Product of Polynomials (25 分)

目录 Problem Description Input Output Sample Sample Input Sample Output Solution Analysis Code Result Problem portal:1009 Product of Polynomials Description Input Output Sample Sample Input Sample Output Solution Analysis Code #include <bits/stdc++.h>

1002 A+B for Polynomials (25)(25 point(s))

problem 1002 A+B for Polynomials (25)(25 point(s)) This time, you are supposed to find A+B where A and B are two polynomials. Input Each input file contains one test case. Each case occupies 2 lines, and each line contains the information of a polyno

1009. Product of Polynomials

1009. Product of Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 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 oc

PAT 1003 Emergency (25)(25 分)

1003 Emergency (25)(25 分) As an emergency rescue team leader of a city, you are given a special map of your country. The map shows several scattered cities connected by some roads. Amount of rescue teams in each city and the length of each road betwe

A1082 Read Number in Chinese (25)(25 分)

A1082 Read Number in Chinese (25)(25 分) Given an integer with no more than 9 digits, you are supposed to read it in the traditional Chinese way. Output "Fu" first if it is negative. For example, -123456789 is read as "Fu yi Yi er Qian san B

【PAT】1015 德才论 (25)(25 分)

1015 德才论 (25)(25 分) 宋代史学家司马光在<资治通鉴>中有一段著名的"德才论":"是故才德全尽谓之圣人,才德兼亡谓之愚人,德胜才谓之君子,才胜德谓之小人.凡取人之术,苟不得圣人,君子而与之,与其得小人,不若得愚人." 现给出一批考生的德才分数,请根据司马光的理论给出录取排名. 输入格式: 输入第1行给出3个正整数,分别为:N(<=10^5^),即考生总数:L(>=60),为录取最低分数线,即德分和才分均不低于L的考生才有资格被