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 wangguanjin at 2005-07-28 00:11:52 on Problem 2507
是不是 有那个测试数据超时呢?帮忙分析一下
#include<stdio.h>
#include<math.h>

float f(float x,float y,float c,float L)
{
	return (sqrt((y*y-L*L)*(x*x-L*L)))/(sqrt(x*x-L*L)+sqrt(y*y-L*L))-c;
}

int main()
{
	float x,y,c;
	float down,min,up,temp,L,temp1;
	while(EOF!=scanf("%f %f %f",&x,&y,&c)){
		down=0.0;
		if(x<y) up=x;
		else up=y;
		min=(down+up)/2;
		L=min;
		temp=f(x,y,c,L);

		temp1=temp;
		if(temp1<0) temp1=-temp1;
		while(temp1>0.0001){
			if(temp<0) up=min;

			if(temp>0) down=min;
			min=(down+up)/2;
			L=min;
			temp=f(x,y,c,L);
			
			temp1=temp;
		    if(temp1<0) temp1=-temp1;
		}
		printf("%.3f\n",L);
		

	}

	return 0;
}
/*

30 40 10
12.619429 8.163332 3
10 10 3
10 10 1

*/

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