Timus Online Judge 1001. Reverse Root

Input

The input stream contains a set of integer numbers Ai (0 ≤ Ai ≤ 1018). 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.

Sample

input output
 1427  0   

   876652098643267843
5276538
2297.0716
936297014.1164
0.0000
37.7757

译文:

输入:

输入一个整数数组,这个数组中每个整数的取值范围为0<= Ai <=10的18次方。这些数字被一些空格和换行符分隔。输入的内存限制为256KB。

输出:

倒序输出数组的平方根。每个平方根结果保留最后四位小数。

==========================

第一次code:

 1 import java.math.BigDecimal;
 2 import java.math.RoundingMode;
 3 import java.util.Scanner;
 4
 5 public class Main
 6 {
 7     public static void main(String[] args)
 8     {
 9         Scanner input = new Scanner(System.in);
10         long[]a = new long[1000000000];
11         int i;
12         for (i=0; input.hasNext(); i++)
13         {
14              a[i] = input.nextLong();
15         }
16         for(i--;i>-1;i--)
17         {
18                         /**
19                         *   Math.sqrt()  :  对数据求平方
20                         *   BigDecimal适用于大型数据计算,精确度高
21                         */
22             BigDecimal   b   =   new   BigDecimal(Math.sqrt(a[i]));
23             System.out.println(b.setScale(4,RoundingMode.HALF_UP).toString());
24         }
25     }
26 }
27     

-------------------------------------我是万恶的分割线---------------------------------------------------------------------------------------------------------

/*

题目稍微修改一下,首先输入一个数,定义数组大小,然后倒序输出该数组的平方根。

*/

 1 import java.math.BigDecimal;
 2 import java.math.RoundingMode;
 3 import java.util.Scanner;
 4
 5 public class Main
 6 {
 7     public static void main(String[] args)
 8     {
 9         Scanner input = new Scanner(System.in);
10         int n =input.nextInt();
11         run();
12     }
13     public static void run()
14     {
15         Scanner input = new Scanner(System.in);
16         long[]a = new long[n];
17         int i;
18         for (i=0; i<n; i++)
19         {
20              a[i] = input.nextLong();
21         }
22         for(i--;i>-1;i--)
23         {
24             BigDecimal   b   =   new   BigDecimal(Math.sqrt(a[i]));
25             System.out.println(b.setScale(4,RoundingMode.HALF_UP).toString());
26         }
27     }
28 }
时间: 2024-12-31 03:44:34

Timus Online Judge 1001. Reverse Root的相关文章

URAL 1001 Reverse Root

输入输出优化:直接加BufferedStream 1 import java.io.BufferedInputStream; 2 import java.io.BufferedOutputStream; 3 import java.io.PrintWriter; 4 import java.util.ArrayList; 5 import java.util.List; 6 import java.util.Scanner; 7   8 public class P1001 9 { 10   1

寒假集训.Reverse Root

B - Reverse Root Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Description 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 n

Reverse Root

Problem 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 inp

Timus Online Judge 1057. Amount of Degrees(数位dp)

1057. Amount of Degrees Time limit: 1.0 second Memory limit: 64 MB Create a code to determine the amount of integers, lying in the set [X;Y] and being a sum of exactlyK different integer degrees of B. Example. Let X=15, Y=20, K=2, B=2. By this exampl

可以使用C#语言的在线ACM题库

俄罗斯乌拉尔大学在线题库 是一个可以使用C#语言的在线ACM题库,有兴趣的朋友可以去试试. Problem 1000. A+B Problem 是入门,就是简单地求整数 A 和 B 的和就行了,答案如下: 1 using System; 2 3 // http://acm.timus.ru/problem.aspx?space=1&num=1000 4 class Acm1000 5 { 6   static void Main() 7   { 8     string[] ss = Conso

Online Judge for ACM-ICPC etc.

原文链接:http://blog.csdn.net/tigerisland45/article/details/52134189 Virtual Judge ACM-ICPC Live Archive - Home UVa Online Judge - Home Welcome To PKU JudgeOnline(POJ) Welcome to Hangzhou Dianzi University Online Judge(HDU) OpenJudge - 百练 - 首页(PKU) Codef

Linux之用户管理与权限控制(上)

早期Linux系统设计为了能够实现多用户.多进程高效的利用服务器资源,在此种情况下,为了能够保证用户与用户之间的文件不被随意的访问及修改.删除等操作,用户.组的管理能在某种程序上实现管理用户或批量管理用户.由于Linux的设计哲学思想『一切皆文件』,用户对设备的访问就是对文件的访问. 一.用户与组 Linux下有三类用户 1.超级用户: root 具有操作系统的一切权限 UID 值为0 2.普通用户: 普通用户具有操作系统有限的权限, UID值 500+ 3.伪用户: 是为了方便系统管理, 满足

一些算法刷题的网站

1. leetcode http://leetcode.com/ 2. careerup http://www.careercup.com/ http://hawstein.com/posts/ctci-solutions-contents.html 3. glassdoor http://www.glassdoor.com/index.htm 4. topcoder http://www.topcoder.com/ 5. zoj http://acm.zju.edu.cn/onlinejudg

递归、非递归 反转单链表

定义链表结构 struct ListNode { int val; ListNode *next; ListNode(int v) : val(v), next(NULL) {} }; 非递归反转单链表 ListNode* reverse(ListNode *root) { if (root == NULL || root->next == NULL) return root; ListNode *cur = root->next; root->next = NULL; while (c