多项式计算,有点像母函数,注意最后要判断最高次项是否为0。

#include <cstdio>
#include <cstring>
using namespace std; #define MAX_NUM 105 int a_num, b_num;
int a[MAX_NUM], b[MAX_NUM];
int c[MAX_NUM * MAX_NUM];
int poly[][MAX_NUM * MAX_NUM];
int poly_num; void input()
{
scanf("%d%d", &a_num, &b_num);
for (int i = ; i <= a_num; i++)
scanf("%d", &a[i]);
for (int i = ; i <= b_num; i++)
scanf("%d", &b[i]);
} void add_c(int poly[], int a)
{
for (int i = ; i <= poly_num; i++)
c[i] += a * poly[i];
} void add_poly(int last[], int next[])
{
memset(next, , sizeof(int) * MAX_NUM * MAX_NUM);
for (int i = ; i <= b_num; i++)
{
for (int j = ; j <= poly_num; j++)
next[i + j] += b[i] * last[j];
}
poly_num += b_num;
} void work()
{
memset(c, , sizeof(c));
for (int i = ; i <= b_num; i++)
{
poly[][i] = b[i];
}
poly_num = b_num;
c[] = a[];
add_c(poly[], a[]);
for (int i = ; i <= a_num; i++)
{
add_poly(poly[(i - ) & ], poly[i & ]);
add_c(poly[i & ], a[i]);
}
while (c[poly_num] == )
poly_num--;
printf("%d", c[]);
for (int i = ; i <= poly_num; i++)
printf(" %d", c[i]);
puts("");
} int main()
{
int case_num;
scanf("%d", &case_num);
for (int i = ; i < case_num; i++)
{
input();
work();
}
}

poj1996的更多相关文章

随机推荐

  1. PAT 甲级 1078 Hashing

    https://pintia.cn/problem-sets/994805342720868352/problems/994805389634158592 The task of this probl ...

  2. django学习--1

    1 安装 安装anacanda后 conda install django 2 新建项目 django-admin.py startproject HelloWorld 创建完成后我们可以查看下项目的 ...

  3. 如何运行spring项目,并打成jar包进行发布

    一.创建spring项目 1.创建项目 2.创建moudule,选择java类型即可. 3.创建lib文件,引入spring的4个核心包spring-beans.spring-context.spri ...

  4. 2013长春网赛1010 hdu 4768 Flyer

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4768 题意:有n个社团发传单,每个社团发给编号为A_i, A_i+C_i,A_i+2*C_i,…A_i ...

  5. NOIP2018划水记

    // 6次NOIP里最爽的一次 去年的NOIP的游记:https://www.cnblogs.com/GXZlegend/p/7880740.html Day 0 特意请了一天假复习NOIP 实际上是 ...

  6. 使用Ubuntu的Crontab定时任务需要注意的地方

    Ubuntu使用crontab定时任务  网上有很多教程,现在记录下我遇到的一些问题,需要注意的地方: 1.定时任务的日志存放路径 网上的说法:cron的日志存放在 /var/log/cron 里面 ...

  7. 算法-动态规划DP小记

    算法-动态规划DP小记 动态规划算法是一种比较灵活的算法,针对具体的问题要具体分析,其宗旨就是要找出要解决问题的状态,然后逆向转化为求解子问题,最终回到已知的初始态,然后再顺序累计各个子问题的解从而得 ...

  8. 【洛谷P1828】香甜的黄油

    题目大意:给定 N 个点,M 条边的无向图,在其中选定 P 个点,每个点可能被选多次,求图中的一个点到选定的 P 个点的距离的值最小是多少. 题解:由于数据范围的限制,直接 Floyd 会超时,因此对 ...

  9. Mac 删除应用卸载后无法正常移除的图标

    经常会不通过appstore下载软件,也就是从网页中下载dmg,自己安装,但是当我不再想要这个软件,然后把它卸载掉之后就会发现,launchpad里还是遗留了这个软件的图标,而且删不掉.这个时候,就可 ...

  10. Windows 7 安装VS2008 SP1 失败

    由于Windows 7自带了.NET Framework 3.5 SP1, 所以在安装VS 2008 SP1的时候会发生fatal error during installation的错误, 网上找来 ...