ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1633. Hippogriffs

PLEASE HELP WA10 (something wrong with accuracy)
Posted by Anastas 19 Oct 2008 19:18
#include<iostream>
#include<iomanip>
#include<cmath>

int a1,b1,a2,b2;
double func(double x);

int main()
{
    using std::cin;
    using std::cout;
    using std::endl;

    cin >> a1 >> b1 >> a2 >> b2;
    double delta = 1e-4;
    double head = 1e-4;
    double tail = 1000000+head;
    while(1)
    {
        double mid = 0.5*(head + tail);
        double cur = func(mid);
        double up = func(mid+delta);
        double down = func(mid - delta);
        if((cur-up)*(cur-down)>=0)
        {
            cout.setf(std::ios::fixed|std::ios::showpoint);
            cout.precision(9);
            cout << cur << endl;
            return 0;
        }else
        {
            if(up>=cur)
            {
                head = mid + delta;
            }
            else
            {
                tail = mid - delta;
            }
        }
    }

}
double func(double x)
{
    return sqrt((a1+b1*x)*(a1+b1*x)/(1 + x*x) + (a2+b2*x)*(a2+b2*x) / (1 + x*x));
}
Re: PLEASE HELP WA10 (something wrong with accuracy)
Posted by Anton 24 Oct 2008 16:09
try lond double for func & x, and long long for a1,a2,b1,b2.
i don't sure, but it must help...