| ||||||||||
| 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 | |||||||||
谁能告诉我,如何使精度符合题义?#include <iostream>
using namespace std;
double ffabs(double a){
if(a>0) return a;
if(a<0) return 0-a;
}
int main(){
double B,W,C,i;
double t1,t2,t3,t4;
double tolerance=0.00001f,ratioB,ratioW;
while(cin>>B>>W>>C){
cout<<B<<" "<<W<<" "<<C<<endl;
if((B==0) && (C==0) && (W==0)) break;
i=0;B*=16;W*=16;
ratioB=1;ratioW=0;
t1=C/(C+W);t2=1-t1;t4=C/B;t3=1-t4;
while(++i<10000){
ratioW=ratioB*t1+ratioW*t2;
ratioB=ratioB*t3+ratioW*t4;
if(ffabs(ratioB-ratioW)<tolerance) break;
}
cout<<i<<endl;
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator