hdu1121 Complete the Sequence
2016-01-27 17:55
531 查看
HDU1121
题意:给你一个整数序列包含S个整数,让你找到这个序列满足的多项式 P(n) = aD.n^D+aD-1.n^D-1+...+a1.n+a0,当这个多项式的阶最小时,输出接下来的满足这个多项式C个整数
差分。计算xi相邻两项差 得序列x2i,计算x2i相邻两项差 得序列x3i,重复以上过程,直到xni的各项值相等。再回算。
题意:给你一个整数序列包含S个整数,让你找到这个序列满足的多项式 P(n) = aD.n^D+aD-1.n^D-1+...+a1.n+a0,当这个多项式的阶最小时,输出接下来的满足这个多项式C个整数
差分。计算xi相邻两项差 得序列x2i,计算x2i相邻两项差 得序列x3i,重复以上过程,直到xni的各项值相等。再回算。
#include<iostream> #include<cstdio> #include<cstring> using namespace std; long long a[105][105]; bool cha(int i,int s) { for(int j=0;j<s-i;j++) if(a[i][j]!=a[i][0]) return false; return true; } int main() { int kase; cin>>kase; while(kase--) { memset(a,0,sizeof(a)); int s,c; cin>>s>>c; for(int j=0;j<s;j++) scanf("%lld",&a[0][j]); int degree=0; int i=0,j=0; while(true) { i++; for(int j=0;j<s-i;j++) a[i][j]=a[i-1][j+1]-a[i-1][j]; if(cha(i,s)) { break; } } int t=i; /*for(int i=0;i<=t;i++) { for(int j=0;j<s-i;j++) cout<<a[i][j]<<' '; cout<<endl; }*/ /* 1 2 7 19 1 5 12 4 7 3 */ for(int j=0;j<s+c;j++) a[s+c-1][j]=a[s+c-1][0]; for(int i=s+c-2;i>=0;i--) for(int j=1;j<s+c;j++) a[i][j]=a[i][j-1]+a[i+1][j-1]; /*for(int i=0;i<=t;i++) { for(int j=0;j<s+c;j++) cout<<a[i][j]<<' '; cout<<endl; }*/ /* 1 2 7 19 41 76 127 1 5 12 22 35 51 70 4 7 10 13 16 19 22 3 3 3 3 3 3 3 */ printf("%lld",a[0][s]); for(int j=s+1;j<s+c;j++) printf(" %lld",a[0][j]); printf("\n"); } return 0; }
相关文章推荐
- HDU 4836 The Query on the Tree lca || 欧拉序列 || 动态树
- PIR Motion Sensor with Arduino
- 1,安装
- 关于UIView的autoresizingMask属性的研究【转】
- leetcode62-Unique Paths
- iOS-值对象NSValue介绍
- [转]SQL SERVER – Find Most Expensive Queries Using DMV
- 引导界面微场景交互设计与技术实现V2.0
- How to control your dust collection with an Arduino (it's easy)
- Arduino started (video)
- 入门动画篇之UIview动画(一)
- UITableView控制头部View
- solr Query
- POJ 3458 Colour Sequence(简单题)
- POJ 1986 Distance Queries(LCA)
- mysql Incorrect string value \xF0\x9F\x98\x84\xF0\x9F
- Zoho Recruit集成性格测试软件,帮你找到最合适的人
- 关于build.gradle的写法
- 使用karma做多浏览器的UI测试
- managedQuery 和 getContentResolver().query的区别