Problem 1856 The Troop

Accept: 72    Submit: 245
Time Limit: 1000 mSec    Memory Limit : 32768 KB

Problem Description

The
troop is advancing. The length of the queue is x meter. The commander
is at the front of the queue, riding his horse. The crier is at the end
of the queue. If something happen, the crier should talk to the
commander. Now, the crier run to the commander. Then run back. We know
the troop has advanced x meter. So what is the number of meter the crier
run. You can assume the speed of the crier is bigger than the troop.

Input

There
are multiple test case, in every case, there will be a real number x.
which means the distance the troop advances. 0 < x < 10^1000

Output

For
each test case you should print the answer. Use the print format as
below. Print a blank line after each case. Because of the Accuracy
error,
If answer >= 100000,you should just output the front five digit. Else
round to the four digits after the decimal point.

Sample Input

100
100000

Sample Output

Case 1
241.4214

Case 2
24142

思路:直接根据样例看出这是1+根号2.
收获:JAVA 对象,类, 构造函数。http://blog.csdn.net/liujun13579/article/details/8155223
import java.math.*;
import java.util.*;
public class Main { public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
BigDecimal x, cell = BigDecimal.ONE;
cell = cell.add(new BigDecimal(Math.sqrt(2.0)));
String str;
int t = ;
while(in.hasNext()) {
x = in.nextBigDecimal();
x = x.multiply(cell);
str = x.toString();
System.out.println("Case "+ t);
t++;
if(x.compareTo(BigDecimal.valueOf(100000.0)) >= )
System.out.println(str.substring(, ));
else{
x = x.divide(BigDecimal.ONE, , RoundingMode.HALF_UP);
System.out.println(x);
}
System.out.println();
} } }

FZU 1856 The Troop (JAVA高精度)的更多相关文章

  1. Java高精度学习第二弹——求N!

    继续学习Java高精度,今天写的是求N!. 首先附上源代码: import java.util.Scanner; import java.math.BigInteger; public class M ...

  2. JAVA高精度模板

    刚开始还坚持用C++写高精来着,后来发现JAVA写高精方便太多了,所以也来学习一下JAVA高精度的模板. 参考:https://www.cnblogs.com/imzscilovecode/p/883 ...

  3. java高精度实数和小数

    java 高精度实数和小数 String s = "1231222222222222222222222222222222222222222222222222222222"; Big ...

  4. java高精度类尝试

    java高精度尝试, poj2109,比较坑的题目 import java.io.*; import java.util.*; import java.math.*; public class Mai ...

  5. HDU 6207:Apple(Java高精度)

    题目链接 题意 给出三个圆上的点,和一个目标的点,问目标点是否在这三个点构成的圆外面. 思路 许久没见过的Java高精度,不要加package!!! import java.math.BigDecim ...

  6. Java高精度基础+开根

    在焦作站的acm网络赛中遇到了一个高精度开根的水题--但是那时候WA了 后面学写java补题还T了orz 所以写一篇文章来记录一下java的大整数类型的基础和开根还有一点心得体会吧 首先给那一题的题面 ...

  7. Codeforces Gym 100418A A - A+-B java高精度

    A - A+-BTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.acti ...

  8. Java高精度学习第三弹——ACM中使用JAVA的详细介绍

    Chapter I. Java的优缺点各种书上都有,这里只说说用Java做ACM-ICPC的特点: (1) 最明显的好处是,学会Java,可以参加Java Challenge . (2) 对于熟悉C/ ...

  9. Java高精度学习第一弹

    为了快速解决高精度问题,总算是要来接触java了,算上这学期要开java的课了,好好学习吧! 拿来练手的是hdu的1002,高精度加法. import java.util.*; import java ...

随机推荐

  1. HDOJ-1015 Safecracker(DFS)

    http://acm.hdu.edu.cn/showproblem.php?pid=1015 题意:给出一个目标值target和一个由大写字母组成的字符串 A-Z分别对应权值1-26 要求从给出的字符 ...

  2. Linux优化,history增加详细历史记录

    主要功能: 1, 可以记录哪个ip和时间(精确到秒)以及哪个用户,作了哪些命令 2,最大日志记录增加到4096条   把下面的代码直接粘贴到/etc/profile后面就可以了 #history mo ...

  3. 第10讲- UI线程阻塞及其优化

    第10讲UI线程阻塞及其优化 .UI 阻塞demo (首先在activity_main.xml中放置两个button,分别命名为button1,button2) //首先设置一个button1用来进行 ...

  4. 《Java程序员面试笔试宝典》之Java程序初始化的顺序是怎样的

    在Java语言中,当实例化对象时,对象所在类的所有成员变量首先要进行初始化,只有当所有类成员完成初始化后,才会调用对象所在类的构造函数创建对象. Java程序的初始化一般遵循以下三个原则(以下三原则优 ...

  5. PHP计算一个目录文件大小方法

    <?php $dirfile='../hnb'; /** *计算一个目录文件大小方法 *$dirfile:传入文件目录名 **/ function dirSize($dirfile) { $di ...

  6. 自定义一个searchBar

    #import "CZSearchBar.h" @implementation CZSearchBar - (instancetype)initWithFrame:(CGRect) ...

  7. 用dTree组件生成无限级导航树

     在做管理系统时不可避免要用到导航树,这种东西只要一次做好,就可以随处运行,目前比较好的组件是dTree,原则上可以达到无限级,当然实际运行中4,5级就已经很多了,dTree的速度还是不错的,而且是J ...

  8. map的类型映射

    以下是使用STL中map类型,对类型的转换示例,主要可以解决的问题,也就是一般的类型之间的相互转换,可以较好的解决相关的问题. 以下是C++源码,比较简短,容易理解的. #include " ...

  9. git学习笔记(五)

    ---恢复内容开始--- 嗯 今天又看到一个非常不错的入门git教程 Mark一下 阮一峰Git操作详解 主要讲解了五个常用的git命令 git clone git remote git fetch ...

  10. PHP学习笔记十六【方法】

    <?php //给一个函数传递基本数据类型 $a=90; $b=90.8; $c=true; $d="hello world"; function test1($a,$b,$ ...