URAL 1001 Reverse Root(水题?)

The problem is so easy, that the authors were lazy to write a statement for it!

Input

The input stream contains a set of integer numbers Ai (0 ≤ Ai ≤ 10^18). The numbers are separated by any number of spaces and line breaks. A size of the input stream does not exceed 256 KB.

Output

For each number Ai from the last one till the first one you should output its square root. Each square root should be printed in a separate line with at least four digits after decimal point.
 
题目大意:给一系列的Ai,求逆序的sqrt(Ai)。
思路:vector存起来逆序输出即可。看上去好像很简单,做起来实际上也是很简单。
double的精度只有15~16位,但是用double做却能AC,为何呢?当然你用long double当我没说。
随便找一个17位的数字22221111222211199
long double开平方得149067472.04608789
double       开平方得149067472.04608792
可见吃掉的精度对答案的影响相当小,完全在4位小数之后,根本就不会影响答案。
简单的说就是开方之后对精度的要求下降了导致double也可以安全AC。
 
代码(0.328S):
 #include <cstdio>
#include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>
#include <cmath>
using namespace std; double a;
vector<double> ans; int main() {
while(scanf("%lf", &a) != EOF) ans.push_back(sqrt(a));
for(vector<double>::reverse_iterator it = ans.rbegin(); it != ans.rend(); ++it)
printf("%.4f\n", *it);
}
上一篇:URAL 1132 Square Root(二次剩余定理)题解


下一篇:[轉]Reverse a singly linked list