【题目】
给出一个长度为n的数组(8<n<12),告诉你规律
(1<=d<=3)要求d尽量小
现在求第n+1项
【题解】
水题
不知道怎么求a1~ad? 用克拉默法则
【代码】
RunID |
User |
Problem |
Result |
Memory |
Time |
Language |
Length |
Submit Time |
2548731 |
Accepted |
0 KB |
6 ms |
1534 B |
2014-07-31 15:10:56 |
#include<cstdio> #include<cstring> #include<cmath> #include<iostream> #include<algorithm> #define eps 0.000001 using namespace std; int i,j,k,n,m,T,ans,big; bool flag; double x,y,z,a[100]; bool equ(double x,double y) { if (fabs(x-y)<eps) return true; return false; } int main() { scanf("%d",&T); while (T--) { scanf("%d",&n); for (i=1;i<=n;i++) scanf("%lf",&a[i]); if (a[1]!=0) { x=a[2]/a[1]; flag=false; for (i=3;i<=n;i++) { if (!equ(a[i],x*a[i-1])) { flag=true; break; } } if (!flag) { printf("%.0lf ",a[n]*x); continue; } } if (a[1]*a[3]-a[2]*a[2]!=0) { flag=false; x=(a[3]*a[3]-a[2]*a[4])/(a[1]*a[3]-a[2]*a[2]); y=(a[1]*a[4]-a[2]*a[3])/(a[1]*a[3]-a[2]*a[2]); for (i=5;i<=n;i++) { if (!equ(a[i],x*a[i-2]+y*a[i-1])) { flag=true; break; } } if (!flag) { printf("%.0lf ",a[n-1]*x+a[n]*y); continue; } } flag=false; x=(a[4]*(a[3]*a[5]-a[4]*a[4])-a[2]*(a[5]*a[5]-a[6]*a[4])+a[3]*(a[5]*a[4]-a[6]*a[3]))/(a[1]*(a[3]*a[5]-a[4]*a[4])-a[2]*(a[2]*a[5]-a[3]*a[4])+a[3]*(a[2]*a[4]-a[3]*a[3])); y=(a[1]*(a[5]*a[5]-a[4]*a[6])-a[4]*(a[2]*a[5]-a[3]*a[4])+a[3]*(a[2]*a[6]-a[3]*a[5]))/(a[1]*(a[3]*a[5]-a[4]*a[4])-a[2]*(a[2]*a[5]-a[3]*a[4])+a[3]*(a[2]*a[4]-a[3]*a[3])); z=(a[1]*(a[3]*a[6]-a[4]*a[5])-a[2]*(a[2]*a[6]-a[3]*a[5])+a[4]*(a[2]*a[4]-a[3]*a[3]))/(a[1]*(a[3]*a[5]-a[4]*a[4])-a[2]*(a[2]*a[5]-a[3]*a[4])+a[3]*(a[2]*a[4]-a[3]*a[3])); printf("%.0lf ",a[n-2]*x+a[n-1]*y+a[n]*z); } }