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 (,) are the exponents and coefficients, respectively. It is given that 1, 0.
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.22 2 1.5 1 0.5
Sample Output:
3 3 3.6 2 6.0 1 1.6
#includeusing namespace std;typedef long long ll;#define maxnum 100005double a[1005] = { 0};double b[1005] = { 0};double c[maxnum] = { 0};int main(){ int n;cin >> n; int t; for(int i=0;i < n;i++){ int x;double y; cin >> x >> y; a[x] = y; if(!i)t = x; } int m;cin >> m; int start; for(int i=0;i < m;i++){ int x;double y; cin >> x >> y; b[x] = y; if(!i) start = x; } for(int i=0;i < t+5;i++){ for(int j=0;j < start+5;j++){ c[i+j] += a[i]*b[j]; } } int cnt = 0; for(int i=0;i < maxnum;i++)if(c[i])cnt++; cout << cnt; for(int i=maxnum-1;i>=0;i--){ if(c[i]) printf(" %d %.1lf",i,c[i]); } return 0;}
空间开的有点小炸,做了一下优化就好了,再一次理解错了提议,K<10,不一定就项系数<10,还好这题没出毒瘤卡边界数据,在超过1e5的地方直接放弃了。。