• 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++]
  • 相关阅读:
    SQL SELECT INTO 语句
    跨站脚本攻击测试[转]
    Visual Studio 2008中如何比较二个数据库的架构【Schema】和数据【Data】并同步 [转贴]
    联表UPDATE
    网站架构策划方案
    概念模型 逻辑模型 物理模型 区别
    Repeater嵌套绑定Repeater
    .net 2.0升级到了.net 3.5,开发工具从vs2005转为vs2008
    你必须知道的C#的25个基础概念(附演示) 【转】
    window2003中,在IIS中,如何解决不能播放.FLV文件
  • 原文地址:https://www.cnblogs.com/lzj-0218/p/3528164.html
Copyright © 2020-2023  润新知