• 高精度 java的一些题


    poj 1001 Exponentiation

    import java.util.*;
    import java.math.*;
    public class Main {
    	public static void main(String[] args) {
    		Scanner in = new Scanner(System.in);
    		while(in.hasNextBigDecimal()) {
    			BigDecimal a = in.nextBigDecimal();
    			int b = in.nextInt();
    			a = a.pow(b);
    			a = a.stripTrailingZeros();
    			String ans = a.toPlainString();
    			if(ans.startsWith("0."))
    				ans = ans.substring(1);
    			System.out.println(ans);
    		}
    
    	}
    
    }
    
    

    poj 1503 Integer Inquiry

    大数加法

    ``` import java.util.*; import java.math.*; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); BigInteger a, b, c; c = BigInteger.valueOf(0); b = BigInteger.valueOf(0); while(true) { a = in.nextBigInteger(); if(a.equals(c)) break; b = b.add(a); } System.out.println(b); }

    }

    <h3> <a href = "http://acm.hdu.edu.cn/showproblem.php?pid=1042", target = "_blank">hdu 1042 N! </a> </h3>
    <h3> 大数乘法 </h3>
    

    import java.util.;
    import java.math.
    ;
    public class Main {
    public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    BigInteger ans, c;
    while(in.hasNextInt()) {
    int n = in.nextInt();
    ans = BigInteger.valueOf(1);
    for(int i = n; i >= 1; i--) {
    c = BigInteger.valueOf(i);
    ans = ans.multiply(c);
    }
    System.out.println(ans);
    }
    }

    }

    
    <h3> <a href = "http://acm.hdu.edu.cn/showproblem.php?pid=1316", target = "_blank">hdu 1316 How Many Fibs? </a> </h3>
    <h3> 大数乘法, 求给出的两个数之间有多少个fib数</h3>
    

    import java.util.;
    import java.math.
    ;
    public class Main {
    public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    BigInteger f[] = new BigInteger[505];
    f[1] = new BigInteger("1");
    f[2] = new BigInteger("2");
    for(int i = 3; i<= 500; i++) {
    f[i] = f[i-1].add(f[i-2]);
    }
    BigInteger a, b, zero;
    zero = BigInteger.valueOf(0);
    while(true) {
    a = in.nextBigInteger();
    b = in.nextBigInteger();
    if(a.equals(zero) && b.equals(zero)) {
    break;
    }
    int tmp = 0;
    for(int i = 1; i <= 500; i++) {
    if(f[i].compareTo(a)>=0 && f[i].compareTo(b)<=0)
    tmp++;
    }
    System.out.println(tmp);
    }
    }

    }

  • 相关阅读:
    python 3.x报错:No module named 'cookielib'或No module named 'urllib2'
    Xshell实现Windows和使用跳板机跳转的远程Linux互传文件
    Linux scp常用命令
    正则表达式
    [NBUT 1458 Teemo]区间第k大问题,划分树
    [hdu5416 CRB and Tree]树上路径异或和,dfs
    [vijos P1008 篝火晚会]置换
    [hdu5411 CRB and Puzzle]DP,矩阵快速幂
    [hdu4713 Permutation]DP
    [hdu4710 Balls Rearrangement]分段统计
  • 原文地址:https://www.cnblogs.com/yohaha/p/5331163.html
Copyright © 2020-2023  润新知