Gym - 101864 M - TFF (模拟)

Problem M - TFF

Let F(x)​ and G(x)​ be two functions of x​ with all positive integer co-efficient and let H(x)​ be their multiplication.

Formally,

F(x) = a​0​ + a​1​*x + a​2​*x​^ 2​ + ..... + a​n-1​*x​^( n-1)

G(x) = b​0​ + b​1​*x + b​2​*x^​ 2​ + ..... + bm​ -1​*x​^( m-1)

H(x) = F(x) * G(x)

= c​0​ + c​1​*x + c​2​*x^​ 2​ + ..... + c​k-1​*x​^( k-1)

 

Where a​n-1 ​ != 0​ and b​m-1 ​ != 0​ and c​k-1 ​ != 0

Given G(x)​ and H(x)​, find F(x)​.

Input Specification

First line will contain an integer t​ denoting the number of test cases. Then the description of the t​ test cases will follow. The first line of every test case will contain the integer m​. The next line will contain m integers which denotes b​0​ , b​1​ , b​2​ , .... , b​m-1​ . Description of H(x) will be given in the following two lines in exactly the same format.

Output Specification

For every test case you need to print the F(x)​ function in the same format as G(x)​ and H(x)​,which were given in the input.

 

Constraints

1 <= t <= 10

1 <= a​ i​ , b​ i​ <= 1000​​​​​​​

1 <= n, m <= 1000

 

Sample

input

1

2

7 3

3

14 41 15

output

2

2 5

Explanation of sample 1

Here,

G(x) = 7 + 3*x​​​​​​​

H(x) = 14 + 41*x + 15*x ^2

= (7+3*x) *(2+5*x)

So, F(x) = 2 + 5 * x​​​​​​​

 

 

题意:给你 G(x) 从 x 的 0 次方 到 x 的 n 次方的系数,H(x) 同理。 其中 H(x) = G(x) * F(x), 求 F(x);

思路:很纯的模拟题, 模拟  多项式除法,注意读题,不会出现 会有余数的情况。

AC代码:

#include<bits/stdc++.h>
using namespace std;

int Hx[5000];
int Gx[5000];
int tmp[5000];

int main()
{
    int t; scanf("%d",&t);
    while(t --){
        memset(tmp,0,sizeof(tmp));
        int n; scanf("%d",&n);
        for(int i = 0;i < n;i ++) scanf("%d",&Gx[i]);
        int f; scanf("%d",&f);
        for(int i = 0;i < f;i ++) scanf("%d",&Hx[i]);
        for(int i = 0;i < n / 2;i ++) swap(Gx[i],Gx[n-i-1]);
        for(int i = 0;i < f / 2;i ++) swap(Hx[i],Hx[f-i-1]);
        int ans[5000] = {0}; int pa = 0;

        for(int i = 0;i < f - n + 1;i ++){
            int t = Hx[i] / Gx[0];
            ans[pa++] = t;

            for(int k = 1;k < n;k ++)
                tmp[k] = t * Gx[k];
            for(int k = 1;k < n;k ++)
                Hx[i+k] -= tmp[k];

        }
        printf("%d\n",pa);
        for(int i = pa - 1;i >= 0;i --)
            if(i == pa - 1) printf("%d",ans[i]);
            else printf(" %d",ans[i]);
        printf("\n");
    }
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值