首页 技术 正文
技术 2022年11月20日
0 收藏 982 点赞 2,650 浏览 1466 个字

FZU 1856 The Troop (JAVA高精度) Problem 1856 The Troop

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

FZU 1856 The Troop (JAVA高精度) 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.

FZU 1856 The Troop (JAVA高精度) 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

FZU 1856 The Troop (JAVA高精度) 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.

FZU 1856 The Troop (JAVA高精度) Sample Input

100
100000

FZU 1856 The Troop (JAVA高精度) 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();
} }}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,982
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,499
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,343
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,126
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,760
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,796