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

用牛顿迭代为什么老是WA?

Posted by youngtrips at 2007-08-13 14:41:11 on Problem 1905
#include <cstdio>
#include <cmath>
const double ep = 1e-12;
const double pi = 3.1415926535897932324626;
int main()
{
	double l,l1,n,c,r,h;
	double x0,x1,k;
	scanf("%lf %lf %lf",&l,&n,&c);
	while(l >= 0 || n >= 0 || c >= 0)
	{
		l1 = l * (1.0 + n * c);
		k = l / l1;
		x0 = pi * 0.125;
		x1 = x0 - (sin(x0) - k * x0) / (cos(x0) - k);
		while(fabs(sin(x1) - k * x1) > ep && fabs(x1 - x0) > ep)
		{
			x0 = x1;
			x1 = x0 - (sin(x0) - k * x0) / (cos(x0) - k);
		}
		r = l1/2/x1;
		h = r * (1 - cos(x1));
		printf("%0.3lf\n",h);
		scanf("%lf %lf %lf",&l,&n,&c);
	}
	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