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 1001. Reverse Root

which part may lead to overTime???
Posted by dreamworld 8 Mar 2011 06:49
#include <iostream>
#include <vector>
using namespace std;
inline double absValue(double x)
{
    if(x>1e-6)
        return x;
    else return -x;
}
int main(int argc, char *argv[])
{
    unsigned long long int i;
    double sqrtTemp;
    vector<double> sqrtValue;
    sqrtValue.reserve(20000);
    while(cin >> i)
    {
        sqrtTemp = i/2;
        if(i)
        {
            do{
               sqrtTemp = (sqrtTemp + i/sqrtTemp)/2 ;
            }while(absValue(sqrtTemp*sqrtTemp - i) > 1e-5);
        }
        sqrtValue.push_back(sqrtTemp);
    }
    vector<double>::reverse_iterator it,end;
    end = sqrtValue.rend();
    for(it=sqrtValue.rbegin();it!=end;it++)
    {
        printf("%.4lf\n",*it);
    }
    system("pause");
    return EXIT_SUCCESS;
}

Edited by author 08.03.2011 07:00