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

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. 利用jquery表格添加一行并在每行第一列大写字母显示实现方法

    表格添加一行并在每行第一列大写字母显示jquery实现方法 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN& ...

  2. Longest Consecutive Sequence 解答

    Question Given an unsorted array of integers, find the length of the longest consecutive elements se ...

  3. HashMap Java Doc

    原文 public class HashMap<K,V> extends AbstractMap<K,V> implements Map<K,V>, Cloneab ...

  4. Socket,非阻塞,fcntl

    一.fcntl 用以下方法将socket设置成为非阻塞方式 int  flags = fcntl(socket,F_GETFL,0); fcntl(socket,F_SETFL,flags|O_NON ...

  5. 游标的使用实例(Sqlserver版本)

    游标,如果是之前给我说这个概念,我的脑子有二个想法:1.你牛:2.我不会 不会不是理由,更不是借口,于是便要学习,本人属性喜欢看代码,不喜欢看书的人,所以嘛,文字对我没有吸引力:闲话少说啊,给大家提供 ...

  6. 【转】多文件目录下makefile文件递归执行编译所有c文件

    首先说说本次嵌套执行makefile文件的目的:只需make根目录下的makefile文件,即可编译所有c文件,包括子目录下的. 意义:自动化编译行为,以后编译自己的c文件时可把这些makefile文 ...

  7. [转]Laravel 4之验证

    Laravel 4之验证 http://dingjiannan.com/2013/laravel-validation/ 基本验证 使用Validator::make($data, $rules)验证 ...

  8. Coding.net代码托管空间申请与使用-安装并运行WordPress博客

    参考: http://www.freehao123.com/coding-net/ Coding.net这是一个国内新兴的代码托管平台,功能主要包括:代码托管.在线运行环境.监控代码质量,兼有一定的社 ...

  9. samba服务器加入域控主机所需要修改的配置文件

    samba服务器加入域控主机,成为域成员,当用户访问samba服务器上的共享文件时,直接到域控主机上进行认证.samba服务器上不需要像先前一样创建系统用户,创建samba用户及密码. 1.安装环境( ...

  10. Eclipse安装Vim——viPlugin插件

    1.下载viPlugin: http://www.viplugin.com/files/viPlugin_2.14.0.zip 2.安装 解压后有两个文件夹: features 和 plugins 把 ...