FZU 1856 The Troop (JAVA高精度)
Problem 1856 The Troop Accept: 72 Submit: 245
Time Limit: 1000 mSec Memory Limit : 32768 KB
Problem Description
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
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
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
100000
Sample Output
241.4214
Case 2
24142
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高精度)的更多相关文章
- Java高精度学习第二弹——求N!
继续学习Java高精度,今天写的是求N!. 首先附上源代码: import java.util.Scanner; import java.math.BigInteger; public class M ...
- JAVA高精度模板
刚开始还坚持用C++写高精来着,后来发现JAVA写高精方便太多了,所以也来学习一下JAVA高精度的模板. 参考:https://www.cnblogs.com/imzscilovecode/p/883 ...
- java高精度实数和小数
java 高精度实数和小数 String s = "1231222222222222222222222222222222222222222222222222222222"; Big ...
- java高精度类尝试
java高精度尝试, poj2109,比较坑的题目 import java.io.*; import java.util.*; import java.math.*; public class Mai ...
- HDU 6207:Apple(Java高精度)
题目链接 题意 给出三个圆上的点,和一个目标的点,问目标点是否在这三个点构成的圆外面. 思路 许久没见过的Java高精度,不要加package!!! import java.math.BigDecim ...
- Java高精度基础+开根
在焦作站的acm网络赛中遇到了一个高精度开根的水题--但是那时候WA了 后面学写java补题还T了orz 所以写一篇文章来记录一下java的大整数类型的基础和开根还有一点心得体会吧 首先给那一题的题面 ...
- 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 ...
- Java高精度学习第三弹——ACM中使用JAVA的详细介绍
Chapter I. Java的优缺点各种书上都有,这里只说说用Java做ACM-ICPC的特点: (1) 最明显的好处是,学会Java,可以参加Java Challenge . (2) 对于熟悉C/ ...
- Java高精度学习第一弹
为了快速解决高精度问题,总算是要来接触java了,算上这学期要开java的课了,好好学习吧! 拿来练手的是hdu的1002,高精度加法. import java.util.*; import java ...
随机推荐
- VMdomainXml
1,One,Euc,Ostack 虚拟磁盘镜像制作方法[Windows,Linux,类linux OS](1,基于ios部署系统生成img,2基于vm xml定义部署系统生成img qcow2) 如需 ...
- jQuery ajax - getScript() 方法和getJSON方法
实例 使用 AJAX 请求来获得 JSON 数据,并输出结果: $("button").click(function(){ $.getJSON("demo_ajax_js ...
- Android应用程序注册广播接收器(registerReceiver)的过程分析
前 面我们介绍了Android系统的广播机制,从本质来说,它是一种消息订阅/发布机制,因此,使用这种消息驱动模型的第一步便是订阅消息:而对 Android应用程序来说,订阅消息其实就是注册广播接收器, ...
- 关于VS2008中的targetver.h文件
targerver.h文件的作用: 定义程序运行的环境,如限制程序只能在XP下运行,限制程序在只能在Vin7下运行 或限制程序只能在XP以上系统运行,或限制程序只能在Server2003以上系统运行. ...
- hdu 2822 Dogs(优先队列)
题目链接:hdu2822 会优先队列话这题很容易AC.... #include<stdio.h> #include<string.h> #include<queue> ...
- NET基础课--NET的一些概念0
0.CIL--公共中间语言 VC++:经过预编译,编译,汇编和链接生成本地可执行代码,支持它运行的是OS和本地cpu指令集. C#: 在.net框架下类似c#的高级语言经过编译生成的文件叫程序集 ...
- T4模板_根据DB生成实体类
为了减少重复劳动,可以通过T4读取数据库表结构,生成实体类,用下面的实例测试了一下 1.首先创建一个项目,并添加文本模板: 2.添加 文本模板: 3.向T4文本模板文件添加代码: <#@ tem ...
- 0104.1——视图控制器UIViewController
一.生命周期 当一个视图控制器被创建,并在屏幕上显示的时候. 代码的执行顺序1. alloc 创建对象,分配空间2.init (initWit ...
- 【转】研华Adam6060某段时间后无法连接的问题
配合乙方测试,需连接现场Adam模块.一段时间后发现模块无法连接,网上资料甚少,发现此贴,记录下.以前没有多客户端高频次(其实谈不上高)连接,没有考虑连接释放的问题.另外,官方Demo也没有释放连接. ...
- java连接sqL2008 数据库实例
package com.lzw; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSe ...