1001. Reverse roottime limit: 2.0 second
Memory limit: 64 mbthe problem is so easy, that the authors were lazy to write a statement for it! Inputthe 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. outputfor each number AI From the last one till the first one you shoshould output its square root. Each square root shoshould
Be printed in a separate line with at least four digits after decimal point. Sample
input |
output |
1427 0 876652098643267843 5276538 |
2297.0716936297014.20.40.41037.7757 |
PS: Thanks again mo Problem Solving Report link: http://acm.timus.ru/problem.aspx? Space = 1 & num = 1001
The question is very easy to understand, mainly to deal with the square root problem, the scope of the data is10 ^ 18. Obviously, it cannot be used.SQRTTo obtain the square root. Our idea is to use two points to find the square root.
Question:
Enter several_ Int64Type data, output their square root. Note that the output order of the question is backward. That is, the square root of the final output of the first input, and the first output of the final input.
Solution:
Open oneDoubleType array. Read_ Int64Type, and then returns a binaryDoubleType is the square root of it, And then savedDoubleArray. To the end of the fileDoubleThe array can be output in reverse order.
# Include <iostream> # include <cstdio> # include <cmath> # include <cstring> # include <string> # include <algorithm> # include <map> using namespace STD; double res [1000004]; double calsr (_ int64 X) // returns the square root of binary data {double left = 0, Right = 1000000000, mid; // right can be an activity, but because the efficiency of binary is very high, it is set to 1000000000 directly. While (left + 0.000001 <right) {mid = (left + right)/2.0; If (mid * mid> X) Right = mid; else left = mid ;} return mid;} int main () {_ int64 P; int t =-1, I; while (scanf ("% i64d", & P )! = EOF) RES [++ T] = calsr (p); // use the res array to save the square root of each data for (I = T; I> = 0; I --) printf ("%. 4f \ n ", Res [I]); Return 0;}/* 1427 0 876652098643267843 5276538 */