Problem K Ural 1001. Reverse Root

Source: Internet
Author: User
Tags integer numbers
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 */

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.