URAL 1001 Reverse Root(水题?)
时间:2014-02-23 07:35:34
收藏:0
阅读:418
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):

1 #include <cstdio> 2 #include <algorithm> 3 #include <cstring> 4 #include <iostream> 5 #include <vector> 6 #include <cmath> 7 using namespace std; 8 9 double a; 10 vector<double> ans; 11 12 int main() { 13 while(scanf("%lf", &a) != EOF) ans.push_back(sqrt(a)); 14 for(vector<double>::reverse_iterator it = ans.rbegin(); it != ans.rend(); ++it) 15 printf("%.4f\n", *it); 16 }
原文:http://www.cnblogs.com/oyking/p/3561245.html
评论(0)