• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
村雨sup
自己选的路,跪着也要走完 XD
博客园    首页    新随笔    联系   管理    订阅  订阅
PAT 1009 Product of Polynomials
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​​​​ ... N​K​​ a​N​K​​​​

where K is the number of nonzero terms in the polynomial, N​i​​ and a​N​i​​​​ (,) 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.2
2 2 1.5 1 0.5

Sample Output:

3 3 3.6 2 6.0 1 1.6
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define maxnum 100005

double 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的地方直接放弃了。。

 
posted on 2019-04-10 01:05  村雨sup  阅读(125)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3