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

精度问题?上面的样例过不了 下面的AC

Posted by allen4053040allen at 2011-08-16 07:28:38 on Problem 2715 and last updated at 2011-08-16 07:36:42
#include<iostream>
#include<cmath>

using namespace std;

#define EPS 0.00001

int main()
{
    double B, W, C;
    while(scanf("%lf%lf%lf", &B, &W, &C) && (B + W + C)) {
        B *= 16, W *= 16;
        double ans = B / (B + W);
        double raW = 0, raB = 1;
        int sum = 0;
        while(fabs(raW - ans) > EPS || fabs(raB - ans) > EPS) {
            raW = 1 - (W * (1 - raW) + C * (1 - raB)) / (C + W);
            raB = ((B - C) * raB + C * raW) / B;
            sum ++;
        }
        printf("%d\n", sum);
    }
}



/*****/
#include<iostream>
#include<cmath>

using namespace std;

#define EPS 0.00001

int main()
{
    double B, W, C;
    while(scanf("%lf%lf%lf", &B, &W, &C) && (B + W + C)) {
        B *= 16, W *= 16;
        double ans = B / W;
        double raW = 0, raB = 1;
        int sum = 0;
        while(fabs(raW / (1 - raW) - ans) > EPS || fabs(raB / (1 - raB) - ans) > EPS) {
            raW = 1 - (W * (1 - raW) + C * (1 - raB)) / (C + W);
            raB = ((B - C) * raB + C * raW) / B;
            sum ++;
        }
        printf("%d\n", sum);
    }
}


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