UVA 10719 Quotient Polynomial
2016-07-15 20:00
169 查看
UVA-10719
题意:给出p(x)的系数和一个数字k,求一个比p(x)少一次就的q(x),使得p(x)=(x-k)*q(x)+r。解题思路:用待定系数可以知道,q(x)中 x^n-1 的系数b[n-1] 会等于p(x)中 x^n 的系数a
。
然后可以推出-k*b[n-1]+b[n-2] =a[n-1] —-> b[n-2]=a[n-1]+k*b[n-1]。
然后正向存,x^n的系数为a[1],那么对于每个b[i]会有b[i]=a[i]+k*b[i-1];b
就是r。
/************************************************************************* > File Name: UVA-10719.cpp > Author: Narsh > > Created Time: 2016年07月15日 星期五 09时38分42秒 ************************************************************************/ #include <iostream> #include <algorithm> #include <cstdio> #include <cstring> using namespace std; int a[10060],b[10060],k,n; char c; int main () { while (scanf("%d\n",&k) != EOF) { c=' '; n=0; b[0]=0; while (c != '\n' ) scanf("%d%c",&a[++n],&c); for (int i = 1; i <= n; i++) b[i]=a[i]+k*b[i-1]; printf("q(x):"); for (int i = 1; i < n; i++) printf(" %d",b[i]); printf("\nr = %d\n\n",b ); } }
相关文章推荐
- 跟Google 学代码: Building Apps with Multimedia(自定义相机和PrintHelper用法)
- 暑期-dp46道(2)
- UVA-537 Artificial Intelligence?
- onclicklistener到底怎么用?
- 简易的C/S系统(实现两个数的和)
- c# 访问SQL Server 其他会话正在使用事务的上下文
- 2016长乐夏令营 Day6
- 自我介绍-决心书
- 开发安全的web应用程序
- Java集合小结
- 【BZOJ-1336&1337】Alie最小圆覆盖 最小圆覆盖(随机增量法)
- IOS中json字符串原生数据请求&IOS跨平台AES128字符串加解密&AFNetworking框架的简单封装使用
- 软件构架、架构和框架的区别
- linux shell 自动输入y/yes
- js改变style样式和css样式
- OpenCV read video
- HDU 1162 Eddy's picture
- spring MVC框架下前台往java后台传送json数据
- 聪明的质监员(codevs 1138)
- 通过 Docker 化一个博客网站来开启我们的 Docker 之旅