本题的测试用例十分刁钻,必须要考虑到很多的细节问题,在这里给出一组测试用例及运行结果:

95.123 12

548815620517731830194541.899025343415715973535967221869852721

0.4321 20
.00000005148554641076956121994511276767154838481760200726351203835429763013462401
5.1234 15
43992025569.928573701266488041146654993318703707511666295476720493953024
6.7592 9
29448126.764121021618164430206909037173276672
98.999 10
90429072743629540498.107596019456651774561044010001
1.0100 12
1.126825030131969720661201
.00001 1
.00001
.12345 1
.12345
0001.1 1
1.1
1.1000 1
1.1
10.000 1
10
000.10 1
.1
000010 1
10
000.10 1
.1
0000.1 1
.1
00.111 1
.111
0.0001 1
.0001
0.0001 3
.000000000001
0.0010 1
.001
0.0010 3
.000000001
0.0100 1
.01
0.0100 3
.000001
0.1000 1
.1
0.1000 3
.001
1.0000 1
1
1.0000 3
1
1.0001 1
1.0001
1.0001 3
1.000300030001
1.0010 1
1.001
1.0010 3
1.003003001
1.0100 1
1.01
1.0100 3
1.030301
1.1000 1
1.1
1.1000 3
1.331
10.000 1
10
10.000 3
1000
10.001 1
10.001
10.001 3
1000.300030001
10.010 1
10.01
10.010 3
1003.003001
10.100 1
10.1
10.100 3
1030.301
99.000 1
99
99.000 3
970299
99.001 1
99.001
99.001 3
970328.403297001
99.010 1
99.01
99.010 3
970593.059701
99.100 1
99.1
99.100 3
973242.271
99.998 1
99.998
0.0010 1
.001

下面是AC代码:

#include<stdio.h>
#include<string.h>
int c[];
int a[];
int b[];
int lenb,lenxiao,len;
void cal() {//计算部分
int i,j,k; memset(c,,sizeof(c));
if(lenxiao==){
len=;
}
else{
len=;
}
for(i=,k=;i<len;i++){
for(j=;j<lenb;j++){
c[i+j+]+=a[i]*b[j];
}
} for(i=len+lenb-;i>;i--){
if(c[i]>=){
c[i-]+=c[i]/;
c[i]=c[i]%;
}
}
if(c[]==){
for(i=;i<=len+lenb-;i++){
b[i-]=c[i];
}
lenb=len+lenb-;
}
else{
for(i=;i<=len+lenb-;i++){
b[i]=c[i];
}
lenb=len+lenb;
}
} void shuchu(int b[],int lenb){// 输出部分
int i,j;
for(i=;i<lenb-lenxiao;i++){
if(b[i]!=)
{
break;
}
}
if(i==lenb){
printf("0\n");
return;
}
for(j=lenb-;j>=lenb-lenxiao;j--){
if(b[j]!=){
break;
}
}
if(j==i&&b[i]==){
printf("0\n");
return ;
}
for(;i<=j;i++){
if(i==lenb-lenxiao){
printf(".");
}
printf("%d",b[i]);
}
printf("\n");
}
int main(int argc,char ** argv){
int power;
int i,j,k;
char input[];
while(scanf("%s",input)!=EOF){
scanf("%d",&power);
memset(a,,sizeof(a));
memset(b,,sizeof(b));
lenxiao=;
lenb=;len=;
for(i=,j=,lenb=;i<=;i++){ if(input[i]=='.'){
lenxiao = -i;
continue;
}
a[j++]=b[j]=input[i]-;
lenb++;
}
lenxiao*=power;
for(i=;i<power-;i++){
cal();
}
shuchu(b,lenb); }
return ;
}

poj 1001 求高精度幂的更多相关文章

  1. poj 1001 求高精度幂(Java, BigDecimal, pow, hasNext, stripTrailingZeros, toPlainString)

    求高精度幂 Time Limit: 500MS   Memory Limit: 10000K Total Submissions: 180325   Accepted: 43460 Descripti ...

  2. Poj.Grids 2951 浮点数求高精度幂

    2951:浮点数求高精度幂 总时间限制: 1000ms 内存限制: 65536kB 描述 有一个实数 R ( 0.0 < R < 99.999 ) ,要求写程序精确计算 R 的 n 次方. ...

  3. 【ACM】求高精度幂

    题目来源:http://poj.org/problem?id=1001&lang=zh-CN 求高精度幂 Time Limit: 500MS   Memory Limit: 10000K To ...

  4. 求高精度幂(java)

    求高精度幂 时间限制:3000 ms  |  内存限制:65535 KB 难度:2   描述 对数值很大.精度很高的数进行高精度计算是一类十分常见的问题.比如,对国债进行计算就是属于这类问题. 现在要 ...

  5. Exponentiation(求高精度幂)

    Exponentiation Time Limit: 500MS   Memory Limit: 10000K Total Submissions: 175340   Accepted: 42341 ...

  6. 求高精度幂(poj1001)

    Description Problems involving the computation of exact values of very large magnitude and precision ...

  7. [POJ 1001] Exponentiation C++解题报告 JAVA解题报告

        Exponentiation Time Limit: 500MS   Memory Limit: 10000K Total Submissions: 126980   Accepted: 30 ...

  8. POJ 1001 Exponentiation(大数运算)

    POJ 1001 Exponentiation 时限:500 ms   内存限制:10000 K 提交材料共计: 179923   接受: 43369 描述:求得数R( 0.0 < R < ...

  9. 【POJ 1001】Exponentiation (高精度乘法+快速幂)

    BUPT2017 wintertraining(15) #6A 题意 求\(R^n\) ( 0.0 < R < 99.999 )(0 < n <= 25) 题解 将R用字符串读 ...

随机推荐

  1. 在CDHtmlDialog中处理WindowClosing

    要截获window.close(),就得截获CDHtmlDialog的WindowClosing.以下是示例代码: // header DECLARE_EVENTSINK_MAP() void Win ...

  2. PHP mail详细示例

    From:http://php.net/manual/zh/function.mail.php Example #1 Sending mail. Using mail() to send a simp ...

  3. 关于打开Eclipse时出现eclipse failed to create the java virtual machine与locking is not possible in the directory问题的解决

    今天在机子上使用Eclipse时候打开发现这两个问题,通过查阅资料膜拜大神博客得知解决方法,特此整理下来,方便后来遇到此问题的小伙伴们. 一开始打开Eclipse时候出现问题现象1,问题1解决以后就出 ...

  4. iOS-网络编程(一)HTTP协议

    一. 网络编程基础 在移动互联网时代,几乎所有应用都需要用到网络,只有通过网络跟外界进行数据交互.数据更新,应用才能保持新鲜.活力.一个好的移动网络应用不仅要有良好的UI和良好的用户体验也要具备实时更 ...

  5. IOS 退出App

    UIApplication *app = [UIApplication sharedApplication]; [app performSelector:@selector(suspend)]; // ...

  6. Windows Live Writer 代码插件改造

    源码和插件都在后面,如果不想看我神神叨叨的可以直接到文章后面下载 一 .找插件 在使用Windows Live Writer 经常要用到插入代码的功能,根据博客园中教程,分别使用了: WindowsL ...

  7. 测试MD5的加密功能

    测试md5主要用于数据库加密.图片修改为RAR格式有源程序.

  8. CSS - 关于li中图文混排不能垂直居中的问题

    图片和文字一起放在li标签下不能同时垂直居中   解决办法: 1.设置图片的position:absolute; 2.把文字加上span标签: span{ height:30px;line-heigh ...

  9. .net对象转Datable

    public static DataTable GetDataTable<T>( IEnumerable<T> list,string tableName) { DataTab ...

  10. wince下写入数据到csv/txt文件中

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...