| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
二分写的有意思,看了半天才懂,精度不够吧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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator