多项式计算,有点像母函数,注意最后要判断最高次项是否为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. sql两个日期之间的查询统计

    sql查询统计 sql语句: select count(code) as '统计',create_time as '订单时间' from sp_orders where datediff(create ...

  2. squid介绍和作用

    介绍 squid服务程序是一款在Unix系统中最为流行的高性能代理服务软件,通常会被当作网站的前置缓存服务,用于替代用户向网站服务器请求页面数据并进行缓存,通俗来讲,Squid服务程序会接收用户的请求 ...

  3. 第八周PSP(11.5--11.9)

    2016.11.5 2016.11.6 2016.11.7 2016.11.8 2016.11.9

  4. PAT 甲级 1096 Consecutive Factors

    https://pintia.cn/problem-sets/994805342720868352/problems/994805370650738688 Among all the factors ...

  5. Linux命令(十八) 压缩或解压缩文件和目录 gzip gunzip

    目录 1.命令简介 2.常用参数介绍 3.实例 4.直达底部 命令简介 和 zip 命令类似,gzip 用于文件的压缩,gzip压缩后的文件扩展名为 ".gz",gzip默认压缩后 ...

  6. emoji & click copy

    emoji & click copy document.execCommand("copy"); https://clipboardjs.com/ https://www. ...

  7. delphi checklistbox用法

    在Delphi中checklistbox中高亮选中(不论是否Checked)能够进行操作么?删除,上下移动等等 删除:CheckListBox.DeleteSelected; 上下移: CheckLi ...

  8. Guava的SetMultimap

    在工作中,我们会经常用到如下类似的结构 Map<String, Set<Stirng>> map = new HashMap<Stirng, Set<String& ...

  9. [代码]--ORA-01745: 无效的主机/绑定变量名 ORA-00917: 缺失的逗号 oracle日期格式错误

    今天在oracle中执行插入语句的时候报了一个奇怪的错误,在程序中报的错误是ORA-01745: 无效的主机/绑定变量名,网上一查说是缺失逗号,在查询分析器执行的时候报缺失的逗号,仔细看了一下也没有缺 ...

  10. MySQL relay_log_purge=0 时的风险

    转自: http://xiezhenye.com/2015/12/mysql-relay_log_purge0-%E6%97%B6%E7%9A%84%E9%A3%8E%E9%99%A9.html 有时 ...