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

why wa??

Posted by ericlee at 2007-05-05 16:17:12 on Problem 2601
poj 2601
精度?
多组测试数据
我都试过了,为什么WA了??谢谢
#include <stdio.h>
#include <memory.h>
#include <math.h>
double c[3010], a[3010];
int main()
{
	int i,n;
	double  a0,an1;
	while(scanf("%d", &n)!=EOF)
	{
		memset(a,0, sizeof(a));
		memset(c, 0, sizeof(c));
		scanf("%lf", &a0);
	scanf("%lf", &an1);
	for(i=1; i<=n; i++)
	{
		scanf("%lf", &c[i]);
	}
	double left = a0 < an1 ? a0 : an1;
	double right = an1 > a0? an1 : a0;
	a[0] = a0;
	while(1)
	{
		a[1] = (left + right)/2;
		for(i=2; i<=n+1; i++)
			a[i] = (a[i-1] + c[i-1])*2 - a[i-2];

		if(right-left<0.00000001)
	//	if((a[n+1] - an1<0.0001 && a[n+1]>an1) ||( an1 - a[n+1]<0.0001 && an1>a[n+1]))
	//	if(fabs(a[n+1]-an1)<0.0001)
			break;
		
		if(a[n+1]<an1)
			left = a[1];
		else
			right = a[1];
	}
	printf("%.2f\n", a[1]);

	}
	
	
	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