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 sunmoonstar_love at 2005-08-27 10:31:21 on Problem 2507
In Reply To:真的不知怎么错啊??求救 Posted by:smilezhen at 2005-08-27 10:05:28
> #include <iostream.h>
> #include <stdio.h>
> #include <math.h>
> 
> int main(void){
> 	double x, y, c, m, n1, n2, h1, h2, c1;
> 	while(cin >> x >> y >> c){
> 		c1 = 0;
> 		if(fabs(x-y)<0.0001){
> 			printf("%.3lf\n",(2*sqrt((x/2)*(x/2) - c*c)));
> 		}else{
> 			n1 = 0;
> 			n2 = 1;
> 			m = (n1 + n2)/2;
> 			while(1){
> 				h1 = sqrt(x*x - (c/m)*(c/m));
> 				h2 = sqrt(y*y - (c/(1-m))*(c/(1-m)));
> 				if(fabs(h1 - h2) < 0.0001) break;
> 				else{
> 					if(h1>h2){
> 						n2 = m;
> 						m = (m+n1)/2;
> 					}
> 					if(h1 <h2){
> 						n1 = m;
> 						m = (m+n2)/2;
> 					}
> 				}
> 			}
> 			printf("%.3lf\n",(h1 +h2)/2);
> 		}
> 	}
> 	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