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. ActionResult解析

    原文地址:http://blog.csdn.net/gulijiang2008/article/details/7642213 ActionResult是一个抽象类, 在Action中返回的都是其派生 ...

  2. print带参数格式

    string_1 = "Camelot" string_2 = "place" print("float:%lf. int:%d string:%s. ...

  3. 浅谈C++调用C#的DLL程序方法

    把C#编译成DLL或者Axtive控件,再由C调用!比如使用C++调用C#的DLL. SwfDotNet是.net下输出flash的类库.SwfDotNet是C#编写的,作者的C#水平,真是令我佩服. ...

  4. Live555 分析(一):类介绍

    从程序的结构来看,live项目包括了四个基本库.程序入口类(在mediaServer中)和一些测试代码(在testProgs中). 四个基本静态库是UsageEnvironment.BasicUsag ...

  5. 用户登陆,退出等基本Action

    用户登陆页面user_login.jsp对应action为login.do: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transiti ...

  6. XSS第二节,XSS左邻右舍

    昨天的文章中引用了OWASP2013年的江湖排名,今天来看一下TOP中XSS的左邻右舍都是谁,先看一下他们的大名,再进一步介绍 [以下主要翻译自https://www.owasp.org/index. ...

  7. 45 个非常有用的 Oracle 查询语句(转)

    这里我们介绍的是 40+ 个非常有用的 Oracle 查询语句,主要涵盖了日期操作,获取服务器信息,获取执行状态,计算数据库大小等等方面的查询.这些是所有 Oracle 开发者都必备的技能,所以快快收 ...

  8. progressbar使用方法:进度画面大小,进度画面背景,进度百分比

    前一段时间,因为项目须要研究了下progressbar,发现这个小东西还真是不简单.在这个小控件的显示效果上,花费的时间远大于预估的工作量.话说程序猿一直是这样,预估的工作量远少于实际...      ...

  9. asp.net同时调用JS和后台的无效的解决

    如果js是个定时器,那么就不走后台 <asp:Button runat="server" type="button" Text="重新发送邮件& ...

  10. HttpURLConnection 下载代码

    private int downloadFile(final String apkurl, final String apkname) { Log.e(LOGTAG, "downloadAp ...