• JAVA 高精度小数模板


     1 package 实验;
     2 import java.math.BigDecimal;
     3 import java.math.BigInteger;
     4 import java.math.MathContext;
     5 import java.math.RoundingMode;
     6 import java.util.Scanner;
     7 import java.util.*;
     8 import java.io.*;
     9 public class Main {
    10     public static void main(String [] args){
    11         Scanner cin = new Scanner(System.in);
    12         int T=cin.nextInt();
    13         while(T>0){
    14             //System.out.println(T);
    15             MathContext mc = new MathContext(10, RoundingMode.HALF_DOWN);
    16             BigDecimal n=cin.nextBigDecimal();
    17             BigDecimal a=cin.nextBigDecimal();
    18             
    19             BigDecimal z1=BigDecimal.valueOf(1.0);
    20             BigDecimal z2=BigDecimal.valueOf(2.0);
    21             
    22 
    23             BigDecimal a2=a.multiply(z2,mc);
    24             BigDecimal t1=z1.divide(a2,mc);
    25             
    26 
    27             t1=t1.add(z1.divide(a,mc),mc);
    28             
    29             BigDecimal t2=z1.divide(t1,mc);
    30             t1=t2.add(a,mc);
    31             
    32             t1=z1.divide(t1,mc);
    33             
    34             //System.out.println(t1);
    35 
    36             
    37             BigDecimal ans=t1.multiply(n,mc);
    38             
    39             ans=z1.divide(ans,mc);
    40             //ans=ans.setScale(10,BigDecimal.ROUND_DOWN);
    41             System.out.println(ans);
    42             T--;
    43         }
    44     }
    45 }
  • 相关阅读:
    <BackTracking> dfs: 39 40
    <Tree> 110 124
    <Tree.PreOrder> DFS 113, 129
    <Math> 50 367
    <String> 49 87
    Haproxy配置Rabbitmq集群负载均衡
    Rabbitmq镜像集群的搭建
    rabbitmq常用命令
    Linux安装rabbitmq
    Docker自定义网络
  • 原文地址:https://www.cnblogs.com/ccsu-kid/p/11628442.html
Copyright © 2020-2023  润新知