zoukankan      html  css  js  c++  java
  • UVa 748 Exponentiation

      Exponentiation 

    Problems involving the computation of exact values of very large magnitude and precision are common. For example, the computation of the national debt is a taxing experience for many computer systems.

    This problem requires that you write a program to compute the exact value of Rn where R is a real number (0.0 < R < 99.999) and n is an integer such that $0 < n le 25$.

    Input 

    The input will consist of a set of pairs of values for R and n. The R value will occupy columns 1 through 6, and the n value will be in columns 8 and 9.

    Output 

    The output will consist of one line for each line of input giving the exact value of Rn. Leading zeros and insignificant trailing zeros should be suppressed in the output.

    Sample Input 

    95.123 12
    0.4321 20
    5.1234 15
    6.7592  9
    98.999 10
    1.0100 12
    

    Sample Output 

    548815620517731830194541.899025343415715973535967221869852721
    .00000005148554641076956121994511276767154838481760200726351203835429763013462401
    43992025569.928573701266488041146654993318703707511666295476720493953024
    29448126.764121021618164430206909037173276672
    90429072743629540498.107596019456651774561044010001
    1.126825030131969720661201
    

    Miguel A. Revilla 
    2000-02-09

    计算高精度幂R^n

    就是高精度乘法反复算即可,输出时算一下小数点的位置将其输出即可

    一个算是坑的地方就是输出时末尾的0在去掉的时候要注意别删多了,比如10.000 10这组测试数据,别输出了1

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cstring>
     4 
     5 using namespace std;
     6 
     7 int main()
     8 {
     9     int r;
    10     int a[200],b[10],c[200];
    11     char s[20];
    12 
    13 
    14     while(gets(s))
    15     {
    16         memset(a,0,sizeof(a));
    17         memset(b,0,sizeof(b));
    18         a[0]=1;
    19 
    20         int t=0,pos;
    21         for(int i=5;i>=0;i--)
    22             if(s[i]!='.')
    23                 b[t++]=s[i]-'0';
    24             else
    25                 pos=i;
    26         sscanf(&s[7],"%d",&r);
    27 
    28         for(int k=1;k<=r;k++)
    29         {
    30             memset(c,0,sizeof(c));
    31             for(int i=0;i<t;i++)
    32             {
    33                 int u=0;
    34                 for(int j=0;i+j<200;j++)
    35                 {
    36                     int temp=c[j+i];
    37                     c[j+i]=(a[j]*b[i]+c[j+i]+u)%10;
    38                     u=(a[j]*b[i]+temp+u)/10;
    39                 }
    40             }
    41             for(int i=0;i<200;i++)
    42                 a[i]=c[i];
    43         }
    44 
    45         int Start,End;
    46         for(Start=199;a[Start]==0;Start--);
    47         for(End=0;a[End]==0;End++);
    48         if(Start<(5-pos)*r)
    49         {
    50             putchar('.');
    51             Start=(5-pos)*r-1;
    52         }
    53         if(End>(5-pos)*r)
    54             End=(5-pos)*r;
    55         for(int i=Start;i>=End;i--)
    56             if(i==(5-pos)*r)
    57                 printf("%d.",a[i]);
    58             else
    59                 printf("%d",a[i]);
    60         putchar('
    ');
    61     }
    62 
    63     return 0;
    64 }
    [C++]
  • 相关阅读:
    hdu 2063 二分图—最大匹配
    sql 中文转拼音首字母
    PhpStorm中如何使用Xdebug工具,入门级操作方法
    Linux怎么查看软件安装路径 查看mysql安装在哪
    仿淘宝实现多行星级评价
    Syslog linux 日志 规格严格
    Windows 退出码 规格严格
    AIX 查看进程监听端口 规格严格
    AIX tar zxvf 规格严格
    IpV6 linux RedHat5 规格严格
  • 原文地址:https://www.cnblogs.com/lzj-0218/p/3528164.html
Copyright © 2011-2022 走看看