POJ1001 Exponentiation (解题报告)

原创 2012年03月24日 22:47:59

POJ1001 Exponentiation (解题报告)

       原文:

Exponentiation

Time Limit: 500MS

 

Memory Limit: 10000K

Total Submissions: 90091

 

Accepted: 21443

Description

Problems involving the computation of exact values ofvery large magnitude and precision are common. For example, the computation ofthe 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 whereR is a real number ( 0.0 < R < 99.999 ) and n is an integer such that 0< n <= 25.

Input

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

Output

The output will consist of one line for each line ofinput giving the exact value of R^n. Leading zeros should be suppressed in theoutput. Insignificant trailing zeros must not be printed. Don't print thedecimal point if the result is an integer.

SampleInput

95.123 12

0.4321 20

5.1234 15

6.7592  9

98.999 10

1.0100 12

SampleOutput

548815620517731830194541.899025343415715973535967221869852721

.00000005148554641076956121994511276767154838481760200726351203835429763013462401

43992025569.928573701266488041146654993318703707511666295476720493953024

29448126.764121021618164430206909037173276672

90429072743629540498.107596019456651774561044010001

1.126825030131969720661201

Hint

If you don't know how to determine wheather encounted theend of input: 
s is a string and n is an integer 

C++


while(cin>>s>>n)


{


...


}


c


while(scanf("%s%d",s,&n)==2) //to see if the scanf read in as many items as you want


/*while(scanf(%s%d",s,&n)!=EOF) //this also work    */


{


...


}



题意:Rn的大小,其中( 0.0 < R< 99.999,0 < n <=25 ) .

解题思路:

 

 

1、  求出小数的位数

2、  输出结果有4中可能

a)      无整数位+无小数位;

b)      无整数位+有小数位;

c)       有整数位+无小数位;

d)      有整数位+有小数位.

注意:S=”000000” 时要特别注意 !

源代码:

#include<stdio.h>

#include<math.h>

#include<stdlib.h>

#include<string.h>

#define MAX 300

int main()

{

       int i,j,k;

       intrepeat,po,point,stop,len;

       char s[6];

       intan1[MAX],an2[6],result[MAX];

       while(scanf("%s%d",s,&repeat)!=EOF)

       {

              memset(an1,0,sizeof(an1));//初始化数组an1

              memset(an2,0,sizeof(an2));//初始化数组an2

              memset(result,0,sizeof(result)); //初始化数组result

              for(j=point=0,i=5;i>=0;i--)//赋值an1、an2.。。。

                     if(s[i]!='.')

                     {an1[j]=s[i]-'0';an2[j]=s[i]-'0';j++;}

                     else

                     {point=5-i;} //并记录小数的位数

              len=j;//记录an2的长度

              for(k=1;k<repeat;k++)

              {

                     memset(result,0,sizeof(result));

                     for(i=0;i<MAX&&i+j<MAX;i++)//开始乘

                            for(j=0;j<len;j++)

                                   result[i+j]+=an1[i]*an2[j];

                     for(i=0;i<MAX;i++)//解决进位问题

                     {

                            if(result[i]>=10)

                            {result[i+1]+=result[i]/10;result[i]=result[i]%10;}

                            an1[i]=result[i];

                     }

              }

              stop=point*repeat;//确定指整数的最后一位的位置

              for(i=0;an1[i]==0&&i<stop;i++);//从末尾跳过小数的后面无意义的零

              po=i;//记录位置

              for(i=MAX-10;an1[i]==0&&i>=stop;i--);//跳过结果前面无意义的零

              if(i==stop-1)//小数点前面没有整数

              {

                     if(po==stop)//小数点后面没有数字

                            printf("0");

                     else//小数点后面有数字

                     {

                            printf(".");

                            for(;i>=po;i--)

                                   printf("%d",an1[i]);

                     }

              }

              else//小数点前面有数字

              {

                     for(;i>=stop;i--)//输出小数点前面的数字

                            printf("%d",an1[i]);

                     if(i>=po)//判断小数点后面有没有数字

                     {

                            printf(".");

                            for(;i>=po;i--)

                            printf("%d",an1[i]);

                     }

              }

              printf("\n");//换行

       }

       return 0;

}

/*

 

95.123 12

0.4321 20

5.1234 15

6.7592  9

98.999 10

1.0100 12

 

 

548815620517731830194541.899025343415715973535967221869852721

.00000005148554641076956121994511276767154838481760200726351203835429763013462401

43992025569.928573701266488041146654993318703707511666295476720493953024

29448126.764121021618164430206909037173276672

90429072743629540498.107596019456651774561044010001

1.126825030131969720661201

 

 */


 

POJ1001 Exponentiation解题报告

POJ1001 Exponentiation解题报告 标签(空格分隔): C++ 参考:大数运算(4)——大数乘法 1.题目内容: Description Problems...
  • gurenyigu
  • gurenyigu
  • 2018年02月10日 15:45
  • 5

[POJ][1001]Exponentiation

Description Problems involving the computation of exact values of very large magnitude and precision...
  • oqqShaw123
  • oqqShaw123
  • 2013年10月04日 11:18
  • 4061

poj1001:1001:Exponentiation解题报告

1001:Exponentiation 查看提交统计提示提问 总时间限制: 500ms 内存限制: 65536kB 描述 Problems involvin...
  • hongbudao
  • hongbudao
  • 2017年08月03日 09:44
  • 272

poj1001 Exponentiation 解题报告

题意:带小数高精度乘法 好久没写过高精度了,还是挺练手的,注意输出的格式。之前WA了一次,看了下discuss里的数据才AC #include #include int c[200],a[200],b...
  • ayecsz
  • ayecsz
  • 2013年08月18日 21:26
  • 282

POJ1001解题报告

乍一看就是大数乘法问题,要通过可不是那么容易
  • zhangxiao93
  • zhangxiao93
  • 2014年07月31日 15:07
  • 914

poj1001解题报告+测试数据

题目链接:http://poj.org/problem?id=1001&lang=zh-CN&change=true当初做完A+B后,兴高采烈地做第二题就被虐了。纠结了一个小时后,含恨退出poj了。 ...
  • keysona
  • keysona
  • 2015年06月05日 08:55
  • 858

【poj1001】 Exponentiation

http://poj.org/problem?id=1001 (题目链接)题意:求实数R的n次方,要求高精度。Solution   SB题Wa了一下午,直接蒯题解。   高精度,小数点以及去前导后...
  • MashiroSky
  • MashiroSky
  • 2016年08月05日 16:44
  • 147

POJ1001:Exponentiation

Time Limit:500ms Memory Limit:10000KDescriptionProblems involving the computation of exact values of...
  • utimes
  • utimes
  • 2016年05月10日 08:42
  • 2543

POJ1001 Exponentiation

/* 高精度乘法(大整数乘法) */ #include #include int sum[1024],n; char num[8]; int main() { while(~scanf("%s%...
  • Time_Limit_Exceeded
  • Time_Limit_Exceeded
  • 2014年07月01日 16:23
  • 245

POJ1001·Exponentiation

Description Problems involving the computation of exact values of very large magnitude and precis...
  • zjh0930
  • zjh0930
  • 2012年06月03日 18:59
  • 137
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:POJ1001 Exponentiation (解题报告)
举报原因:
原因补充:

(最多只允许输入30个字)