教你如何求多项式的系数
在数学书我们曾经学过求多项式系数的问题吧,但是编程上怎么办呢?
先给一道例题看看吧
Easy Task
Calculating the derivation of a polynomial is an easy task. Given a function f(x) , we use (f(x))’ to denote its derivation. We use x^n to denote xn. To calculate the derivation of a polynomial, you should know 3 rules:
(1) (C)’=0 where C is a constant.
(2) (Cx^n)’=C*n*x^(n-1) where n>=1 and C is a constant.
(3) (f1(x)+f2(x))’=(f1(x))’+(f2(x))’.
It is easy to prove that the derivation a polynomial is also a polynomial.
Here comes the problem, given a polynomial f(x) with non-negative coefficients, can you write a program to calculate the derivation of it?
Input
Standard input will contain multiple test cases. The first line of the input is a single integerT (1 <= T <= 1000) which is the number of test cases. And it will be followed byT consecutive test cases.
There are exactly 2 lines in each test case. The first line of each test case is a single line containing an integerN (0 <= N <= 100). The second line contains N + 1 non-negative integers,CN, CN-1, …, C1, C0, ( 0 <= Ci <= 1000), which are the coefficients of f(x).Ci is the coefficient of the term with degree i in f(x). (CN!=0)
Output
For each test case calculate the result polynomial g(x) also in a single line.
(1) If g(x) = 0 just output integer 0.otherwise
(2) suppose g(x)= Cmx^m+Cm-1x^(m-1)+…+C0 (Cm!=0),then output the integersCm,Cm-1,…C0.
(3) There is a single space between two integers but no spaces after the last integer.
Sample Input
3
0
10
2
3 2 1
3
10 0 1 2
Sample Output
0
6 2
30 0 1
这道例题的意思是先给你一个T,然后是有T组测试样例,然后给你一个n,表示有n+1个数,让你求多项式的系数,注意,如果n=0,输出的是0.
下面给代码喽
#include<stdio.h>
int main()
{int t, n, i, j, a[1000], b[1000];while(~scanf("%d", &t)){for(i=0;i<t;i++){scanf("%d", &n);for(j=0;j<=n;j++){scanf("%d", &a[j]);b[j]=a[j]*(n-j);}if(n==0){printf("0");}else{for(j=0;j<n;j++){printf("%d", b[j]);if(j!=n-1){printf(" ");}}}printf("\n");}}return 0;
}
教你如何求多项式的系数相关推荐
- 设非零得实系数多项式 $f(x)$ (即系数都是实数得多项式)满足 $f(f(x)) = f^k(x)$,其中 $k$ 是给定得正整数。求多项式 $f(x)$
设非零得实系数多项式 f(x)f(x)f(x) (即系数都是实数得多项式)满足 f(f(x))=fk(x)f(f(x)) = f^k(x)f(f(x))=fk(x),其中 kkk 是给定得正整数.求多 ...
- python写程序求多项式的和_用正则编译和搜索在python中计算区分多项式的系数
测试多项式'2x^3+4x^2+8x-16'下面的代码输出6.8作为区分多项式的系数.但是,输出应该是6.8.8.为什么函数getNewCoEffents会产生错误的结果?什么是产生正确结果的好方法? ...
- 用C语言解“二分法求多项式单根”题
7-18 二分法求多项式单根 二分法求函数根的原理为:如果连续函数f(x)在区间[a,b]的两个端点取值异号,即f(a)f(b)<0,则它在这个区间内至少存在1个根r,即f®=0. 二分法的步骤 ...
- 用Python解“二分法求多项式单根 ”题
7-18 二分法求多项式单根 二分法求函数根的原理为:如果连续函数f(x)在区间[a,b]的两个端点取值异号,即f(a)f(b)<0,则它在这个区间内至少存在1个根r,即f®=0. 二分法的步骤 ...
- 7-166 二分法求多项式单根 (20 分)
7-166 二分法求多项式单根 (20 分) 二分法求函数根的原理为:如果连续函数f(x)在区间[a,b]的两个端点取值异号,即f(a)f(b)<0,则它在这个区间内至少存在1个根r,即f(r) ...
- matlab根据根求多项式,matlab求解多项式的根
因此牛顿法也称切线法,是非线性方程求根方法中收敛最快的方 法. 2. matlab 中方程求解的基本命令 roots(p):求多项式方程的根,其中 p 是多项式系数按降幂排列所形成的向量. solve ...
- 求多项式浮点java思路,求多项式函数实数根的方法
第29卷 第5期 Vol. 29No. 5昭通师范高等专科学校学报Journal of Zhaotong Teacher πs College 2007年10月Oct. 2007●数学 求多项式函数实 ...
- PTA——二分法求多项式单根
PTA--二分法求多项式单根 题目: 二分法求函数根的原理为:如果连续函数f(x)在区间[a,b]的两个端点取值异号,即f(a)f(b)<0,则它在这个区间内至少存在1个根r,即f®=0. 二分 ...
- 求多项式f(x)=anxn +an-1xn-1+…+a1x+a0和f(x)=((anx+an-1)x+…+a1)x+a0
求多项式f(x)=anxn +an-1xn-1+-+a1x+a0 算法思想: 将系数放进数组a[n]中,for循环每次系数与x的幂次相乘,再将每次相乘的结果相加即可. public double fu ...
最新文章
- 基于 Prometheus 的监控系统实践
- Spring实战3-Spring之旅
- 关于阻塞I/O 非阻塞I/O 同步I/O 异步I/O epoll select的学习
- 黄金点游戏之客户端(homework-05)
- android studio 制作表格_红爆网络的旅游排行榜视频制作其实很简单,赶快动手尝试...
- linux下安装mysql5.7.19,Linux下MySQL5.1升级到高版本MySQL5.7.19详解 | zifangsky的个人博客...
- win8、win10如何修改文件夹的权限
- HarmonyOS 开发避坑指南
- android 插入gif,android – Gboard:在EditText上启用GIF插入
- Vue.js学习系列(八)---使用路由搭建单页应用(一)
- O - Muddy Fields
- TraceView的使用
- 神经网络训练ai玩游戏,人工神经网络入门
- 从数字艺术品到 NFT
- cdr2018更新内容
- windows系统ftp服务器,Windows下使用的FTP服务器软件
- 数电实验三 数据选择器及其应用 任务一:用74151芯片采用降维的方法实现F=ABC+ABD+ACD+BCD; 任务二:用74151芯片采用降维方式实现F=BCD反+BC反+A反D;
- 使用vuepress搭建静态博客
- 2017 ACM Arabella Collegiate Programming Contest G. Snake Rana GYM101350G
- win7下快速启动栏的快捷方式的位置