博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
FZU 1856 The Troop (JAVA高精度)
阅读量:5112 次
发布时间:2019-06-13

本文共 1928 字,大约阅读时间需要 6 分钟。

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 对象,类, 构造函数。
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 = 1;        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)) >= 0)                System.out.println(str.substring(0, 5));            else{                x = x.divide(BigDecimal.ONE, 4, RoundingMode.HALF_UP);                System.out.println(x);            }            System.out.println();        }    }}

 

转载于:https://www.cnblogs.com/ZP-Better/p/4723481.html

你可能感兴趣的文章
移动设备显示尺寸大全 CSS3媒体查询
查看>>
hihoCoder #1831 : 80 Days-RMQ (ACM/ICPC 2018亚洲区预选赛北京赛站网络赛)
查看>>
图片等比例缩放及图片上下剧中
查看>>
jQuery方法大全
查看>>
[转贴]安装ssh
查看>>
WebView加载网页详情
查看>>
【转载】Linux screen 命令详解
查看>>
dd命令 建立两颗一模一样的磁盘
查看>>
常用的jquery触屏手机页面特效代码下载
查看>>
background-clip,background-origin
查看>>
C# 如何创建一个Windows服务
查看>>
集群和分布式区别
查看>>
Android(java)学习笔记153:采用post请求提交数据到服务器(qq登录案例)
查看>>
Java基础知识强化101:Java 中的 String对象真的不可变吗 ?
查看>>
Android 高级UI设计笔记12:ImageSwitcher图片切换器
查看>>
虚拟主机与虚拟目录学习小结
查看>>
hlg1414安装雷达【贪心】
查看>>
Blog文章待看
查看>>
Project 1 最后总结 病好了总算发了!
查看>>
《数据结构》线段树入门(一)
查看>>