zoukankan      html  css  js  c++  java
  • 《算法竞赛入门经典》(刘汝佳)——高精度计算(基础)

    1:小学生算术

    poj 2562 Primary Arithmetic

    #include<stdio.h>
    #include<string.h>
    #define ll long long 
    int main()
    {
        ll a,b,aa,bb;
        while(scanf("%lld%lld",&a,&b)!=EOF)
        {
            if(a==0&&b==0)break;
            aa=a>b? a:b;
            bb=a<b? a:b;
            ll jin=0,ans=0;
            while(bb)
            {
                if(jin)
                    ans++;
                ll c=aa%10;aa/=10;
                ll d=bb%10;bb/=10;
                jin=(jin+c+d)/10;
            }
            while(aa)
            {
                if(jin)
                    ans++;
                ll c=aa%10;aa/=10;
                jin=(jin+c)/10;
            }
            if(jin)
                ans++;
            if(ans==0)
                printf("No carry operation.
    ");
            else if(ans==1)
                printf("1 carry operation.
    ");
            else 
                printf("%d carry operations.
    ",ans);
        }
        return 0;
    }
    View Code

    2:阶乘的精确值

    hdu 1042 n!

    这道我是以前做过的,用的是java

    import java.util.*;
    import java.math.*;
    public class Main
    {
        public static void main(String[] args)
        {
            Scanner shuru = new Scanner (System.in);
            int A,i;
            while(shuru.hasNext())
            {
                A=shuru.nextInt();
                BigInteger B=BigInteger.ONE;
                for(i=1;i<=A;i++)
                {
                    B=B.multiply(BigInteger.valueOf(i));
                }
                System.out.println(B);
            }
            
            
        }
    }
    View Code

    另外字符模拟处理就不写了,因为多花些时间就可以写好,懒得写了

     3:高精度运算类bign

    大数运算的模版,可以计算大数+,-,*,/,%,但是对于 - ,前一个数要比后一个数大!

    一道又一道,好高兴!
  • 相关阅读:
    Service Name Port Number Transport Protocol tcp udp 端口号16bit
    linux linux 互传文件 win 不通过 ftp sftp 往linux 传文件(文件夹)
    soft deletion Google SRE 保障数据完整性的手段
    Taylor series
    Taylor's theorem
    Moving average
    REQUEST
    Unix file types
    mysqld.sock
    Tunneling protocol
  • 原文地址:https://www.cnblogs.com/laiba2004/p/3585512.html
Copyright © 2011-2022 走看看