poj1996
多项式计算,有点像母函数,注意最后要判断最高次项是否为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的更多相关文章
随机推荐
- PHP 爬虫——QueryList
前言: 来了个任务说要做个电影网站,要写个壳,数据直接从别人那扒.行吧!那就要学习下PHP爬虫了.占个博客,以后补充.http://study.querylist.cc/archives/6/ 之前开 ...
- [转帖]SSL/TLS/WTLS原理
SSL/TLS/WTLS原理 作者:yawl < yawl@nsfocus.com >主页:http://www.nsfocus.com日期:2001-02-19 一 前言 首先要澄清一下 ...
- 小程序开发 event对象中 target和currentTarget 属性的区别。
首先本质区别是: event.target返回触发事件的元素 event.currentTarget返回绑定事件的元素 p包含在div内 在outer上点击时,target跟currentTarget ...
- leetcode Database4
一.Department Top Three Salaries The Employee table holds all employees. Every employee has an Id, an ...
- kubernetes部署
[自动安装] 一:操作环境 操作系统 centos7 防火墙selinux #systemctl stop firewalld && systemctl disable fire ...
- 使用 Sixel 图形格式在终端中显示缩略图
不久前,我们讨论了 Fim,这是一个轻量级的命令行图像查看器应用程序,用于从命令行显示各种类型的图像,如 bmp.gif.jpeg 和 png 等.今天,我偶然发现了一个名为 lsix的类似工具.它类 ...
- 【Luogu4609】建筑师(第一类斯特林数,组合数学)
[Luogu4609]建筑师(组合数学) 题面 洛谷 题解 首先发现整个数组一定被最高值切成左右两半,因此除去最高值之后在左右分开考虑. 考虑一个暴力\(dp\) ,设\(f[i][j]\)表示用了\ ...
- 洛谷 P1457 城堡 The Castle 解题报告
P1457 城堡 The Castle 题目描述 我们憨厚的USACO主人公农夫约翰(Farmer John)以无法想象的运气,在他生日那天收到了一份特别的礼物:一张"幸运爱尔兰" ...
- 洛谷P3928 Sequence2(dp,线段树)
题目链接: 洛谷 题目大意在描述底下有.此处不赘述. 明显是个类似于LIS的dp. 令 $dp[i][j]$ 表示: $j=1$ 时表示已经处理了 $i$ 个数,上一个选的数来自序列 $A[0]$ 的 ...
- bzoj 4464 : [Jsoi2013]旅行时的困惑
网络流建图. 从S向每个点连边,从每个点向T连边. 每条树边反向连一条下界为1,上界inf的边. 跑最小流. 注意加当前弧优化. #include<cstdio> #include< ...