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

公式一次AC,推公式还是比较简单的

Posted by bluegenelove at 2007-08-03 01:01:19 on Problem 2601
反复的代入可以推出公式
(n+1)a[i]=na[i-1]+a[i+n]-2*(c[i+n-1]+2*c[i+n-2]+3*c[i+n-3]+...+j*c[i+n-j]+...n*c[i])
根据题意
(n+1)a[1]=na[0]+a[n+1]-2*(c[n]+2*c[n-1]+3*c[n-2]+...+j*c[n+1-j]+...n*c[1])

代码如下:

#include <stdio.h>

int main ()
{
	int n,i;
	float a,b,c[3005],sum;

	while (scanf ("%d",&n)!=EOF)
	{
		sum=0;
		scanf ("%f%f",&a,&b);
		for (i=1;i<=n;i++)
		{
			scanf ("%f",&c[i]);
			sum+=(n-i+1)*c[i];
		}
		sum=(n*a+b-2*sum)/(n+1);

		printf ("%.2f\n",sum);
	}

	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