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

简单模拟。

#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdio>
using namespace std;

double a[3000],b[3000],c[3000];
int k;

int main()
{
    for(int i=0;i<=2000;i++) a[i]=b[i]=c[i]=0;
    int Max=-1;
    scanf("%d",&k);
    for(int i=1;i<=k;i++)
    {
        int id;double num;
        scanf("%d%lf",&id,&num);
        a[id]=num;
    }

    scanf("%d",&k);
    for(int i=1;i<=k;i++)
    {
        int id;double num;
        scanf("%d%lf",&id,&num);
        b[id]=num;
    }

    for(int i=0;i<=1000;i++)
    {
        for(int j=0;j<=1000;j++)
        {
            c[i+j]+=a[i]*b[j];
        }
    }

    int cnt=0;
    for(int i=2000;i>=0;i--)
        if(c[i]!=0) cnt++;

    printf("%d",cnt);
    int op=0;
    for(int i=2000;i>=0;i--)
        if(c[i]!=0)
            printf(" %d %.1lf",i,c[i]);
    return 0;
}
时间: 2025-01-06 22:56:03

PAT (Advanced Level) 1009. Product of Polynomials (25)的相关文章

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

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)(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

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>

PAT Advanced 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 polynomial: K N?1?? a?N?1???? N?2?? a?N?2?

PAT:1009. Product of Polynomials (25) AC

#include<stdio.h> #include<stdlib.h> #include<string.h> //[warning]double 输入%lf,输出%f struct arr { int exp; //指数 double cof; //系数 }arr[1005]; double ans[2010]; //下标是指数,内容是系数 int main() { memset(arr,0,sizeof(arr)); memset(ans,0,sizeof(ans)

PAT甲题题解-1009. Product of Polynomials (25)-多项式相乘

多项式相乘 注意相乘结果的多项式要开两倍的大小!!! #include <iostream> #include <cstdio> #include <algorithm> #include <cstring> #include <string.h> using namespace std; //两个多项式相乘 const int maxn=1000+5; int k; //原本定义个exp导致编译错误,没想到定义成exp1.exp2也会编译错误,

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~ ..