Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

为什么用拉格朗日过不去?

Posted by zcl_wxy at 2005-07-17 11:22:44 on Problem 1398
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int dcmp(double s,double x)
{
	double t,px=0.1;
	t=x-s;
	if(fabs(t)<px)  return 1;
    else  return 0;
}
int main()
{
    int q,S,C,i,j,k,x[120],h,coin,n,w,m,p;
    double s,t,r;
    while(scanf("%d",&p)==1)
    {
      for(q=1;q<=p;q++)
	  {
	  scanf("%d%d",&S,&C);  
	  h=1;
      scanf("%d",&x[1]);
      for(i=2;i<=S;i++)
      {
	    scanf("%d",&x[i]);
	    if(x[i]!=x[i-1])  h=0;
	  }
      if(h==1)
      {
	    for(i=S+1;i<C+S;i++) printf("%d ",x[1]);
     	printf("%d\n",x[1]);
      }
      else
      {
	    for(n=1;n<S;n++)
		{
		  coin=1;
		  for(j=n+2;j<=S;j++)
		  {
	        r=0;
			for(k=1;k<=n+1;k++)
            {
              s=1.0;
			  for(m=1;m<=n+1;m++)
			  { 
			    if(m!=k) 
                {
				  s*=(j-m);
				  t=(k-m);
				  s/=t;
                }
			  }	
			  s*=x[k];
			  r+=s;
			}
			w=dcmp(r,x[j]);
	        if(w==0) { coin=0;break; }
			else coin=1;
		  }
	      if(coin==1)  break;
		}
      }
	  for(i=S+1;i<=C+S&&h==0;i++)
      {
		r=0;
		for(j=1;j<=n+1;j++)
		{
	      s=1.0;
	      for(k=1;k<=n+1;k++)
          {
	        if(k!=j)  
			{
			  t=(j-k);
			  s*=(i-k);
			  s/=t;
			}
		  }
	      s*=x[j];
		  r+=s;
        }
		x[i]=(int)(r+0.2);
      }
	  for(i=S+1;i<C+S&&h==0;i++)  printf("%d ",x[i]);
	  if(h==0)  printf("%d\n",x[i]);
	}
	}
    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator