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 wanpi0user at 2005-11-23 23:26:14 on Problem 2715
#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:
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