| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
why#include <stdio.h>
void main()
{
int y[11],n,i,j,x;
double m,l;
while(scanf("%d",&n),n!=0)
{
for(i=1;i<=n;i++)
scanf("%d",&y[i]);
scanf("%d",&x);
for(i=2;i<=n;i++)
if(y[i]!=y[1])
break;
if(i>n)
{
printf("Term %d of the sequence is %d\n",x+n,y[1]);
continue;
}//////我用的拉格朗日插值公式,但为什么要加上这个if后才AC呢
x+=n;
m = 0;
for(i=1;i<=n;i++)
{
l=1;
for(j=1;j<=n;j++)
{
if(i==j)
continue;
l*=(x-j);
l/=(i-j);
}
l *= y[i];
m+=l;
}
printf("Term %d of the sequence is %.0lf\n",x,m);
}
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator