题意

给出n(1–150). 
输出两个多项式A,B从常数到最高次的系数,使得对两个多项式求gcd时,恰好经过n步得到结果. 
多项式的gcd一步是指(A(x),B(x))变成(B,A mod B)的过程,且当A mod B为0时,视为得到结果B. 
A mod B为多项式求余,参见 long division
要求两个多项式的所有系数都是1,0,-1.前导系数(最高次项系数)为1,度数(最高次)不超过n,第一个多项式的度数大于第二个

分析:
这个题懵逼了好几天,题解愣是没看懂,来学校后在宿舍用笔划拉了好久终于大概是了解了是怎么回事了。
 逆推一下GCD的公式:GCD(A,B)=GCD(AX+B,A)。所以可以得到An=An-1*X+An-2。但是题目中有个限制每一位的系数的绝对值不大于1。将GCD变形可以得到GCD(AX+B,A)=GCD(AX-B,A),所以在递推的时候如果系数超过1,那么相减,否则相加。

 #include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream> using namespace std;
const int maxn=+;
int a[maxn][maxn];
int n; int main(){
scanf("%d",&n);
a[][]=;a[][]=;
for(int i=;i<=n;i++){
for(int j=;j<=i;j++){
if(j>)
a[i][j]=a[i-][j-];
if(j<=i-){
if(a[i][j]+a[i-][j]>)
a[i][j]-=a[i-][j];
else
a[i][j]+=a[i-][j];
}
}
}
printf("%d\n",n);
for(int i=;i<=n;i++){
printf("%d ",a[n][i]);
}
printf("\n");
printf("%d\n",n-);
for(int i=;i<n;i++){
printf("%d ",a[n-][i]);
}
return ;
}

codeforce453DIV2——D. GCD of Polynomials的更多相关文章

  1. Codeforces D - GCD of Polynomials

    D - GCD of Polynomials 逆推,根据(i-2)次多项f(i-2)式和(i-1)次多项式f(i-1)推出i次多项式f(i) f(i)=f(i-1)*x+f(i-2) 样例已经给出0次 ...

  2. 【CodeForces】901 B. GCD of Polynomials

    [题目]B. GCD of Polynomials [题意]给定n,要求两个最高次项不超过n的多项式(第一个>第二个),使得到它们GCD的辗转次数为n.n<=150. [算法]构造 [题解 ...

  3. Codeforces 902D/901B - GCD of Polynomials

    传送门:http://codeforces.com/contest/902/problem/D 本题是一个数学问题——多项式整除. 对于两个整数a.b,求最大公约数gcd(a,b)的辗转相除法的函数如 ...

  4. Algebraic Kernel ( Arithmetic and Algebra) CGAL 4.13 -User Manual

    1 Introduction Real solving of polynomials is a fundamental problem with a wide application range. T ...

  5. Polynomial ( Arithmetic and Algebra) CGAL 4.13 -User Manual

    1 Fundamentals A polynomial is either zero, or can be written as the sum of one or more non-zero ter ...

  6. Codeforces Round #453 (Div. 1)

    Codeforces Round #453 (Div. 1) A. Hashing Trees 题目描述:给出一棵树的高度和每一层的节点数,问是否有两棵树都满足这个条件,若有,则输出这两棵树,否则输出 ...

  7. Codeforces Round #453 ( Div. 2) Editorial ABCD

    A. Visiting a Friend time limit per test 1 second memory limit per test 256 megabytes input standard ...

  8. Codeforces Round #453 Div. 2 A B C D (暂时)

    // 从大作业和实验报告中爬出来水一发 // 补题...还是得排在写完实验报告之后... A. Visiting a Friend 题意 给定若干段行车区间,问能否从起点到终点 思路 扫描一遍,维护最 ...

  9. Codeforces Round #453

    Visiting a Friend Solution Coloring a Tree 自顶向下 Solution Hashing Trees 连续2层节点数都超过1时能异构 Solution GCD ...

随机推荐

  1. sysbench安装for oracle

    RHEL7.2+ 1.依赖包安装 * autoconf * automake * cdbs * debhelper (>= 9) * docbook-xml * docbook-xsl * li ...

  2. ng 双向数据绑定 实现 注册协议效果

    效果: 代码: <!DOCTYPE html> <html ng-app="myApp"> <head lang="en"> ...

  3. CENTOS7.3 64位架设使用MYSQL数据库的ASP.NET CORE网站

    注:本人使用的是云服务器,具体CentOS怎么安装这里不作赘述. 网站架设效果可以查看https://www.resape.com 一.在CentOS上安装Dotnet Core环境 1.Add th ...

  4. java如何填写简历?(干货篇)

        化身孤岛的鲸不才 - 十三夜之月 一份优秀的简历不一定能帮你找到一份满意的工作,但能大大提升你的面试机会. 不容否认,简历是对你的能力.教育和经历的一份简要信息概述. 简历中应该突出你最核心的 ...

  5. 【转】C# Socket编程(2)识别网络主机

    [转自:https://www.cnblogs.com/IPrograming/archive/2012/10/11/CSharp_Socket_2.html] 一个客户端想要发起一次通信,先决条件就 ...

  6. 【spring源码学习】spring的IOC容器之自定义xml配置标签扩展namspaceHandler向IOC容器中注册bean

    [spring以及第三方jar的案例]在spring中的aop相关配置的标签,线程池相关配置的标签,都是基于该种方式实现的.包括dubbo的配置标签都是基于该方式实现的.[一]原理 ===>sp ...

  7. Pycharm简单使用教程

    转自https://blog.csdn.net/qq_40130759/article/details/79421242 1.下载pycharm pycharm是一种Python IDE,能够帮助我们 ...

  8. 区域存储网络(SAN)与 网络直接存储(NAS)

    随着互联网及网络应用的飞速发展,数据信息存储系统所需处理的数据类型也呈爆炸性增长,这使数据信息存储系统面临前所未有的挑战.附加式网络存储装置(Network Attached Storage,缩写为N ...

  9. ORA-00845 : MEMORY_TARGET not supported on this system(调大数据库内存无法启动)

    问题描述:调大数据库内存后,启动数据库报 ORA-00845 : MEMORY_TARGET not supported on this system . -- 调大数据库内存后,数据库启动报错[ro ...

  10. bzoj 3277 & bzoj 3473,bzoj 2780 —— 广义后缀自动机

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3277 https://www.lydsy.com/JudgeOnline/problem.p ...