总时间限制:
1000ms
内存限制:
65536kB
描述
有一个实数 R ( 0.0 < R < 99.999 ) ,要求写程序精确计算 R 的 n 次方。n 是整数并且 0 < n <= 25。
输入
T输入包括多组 R 和 n。 R 的值占第 1 到 第 6 列,  n 的值占第 8 和第 9 列。
输出
对于每组输入,要求输出一行,该行包含精确的 R 的 n 次方。输出需要去掉前导的 0 后后面不不要的 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
 //@author langx
//G++4.4
#include <cstdio>
#include <cstring>
#define SIZE 126
#define LEN 5 int a[SIZE],b[LEN]; int mul( int alen,int blen){
int tmp[SIZE], i, j, k;
memset(tmp,,sizeof(tmp));
for( i = ; i < alen; ++i){
for( j = ; j < blen; ++j){
tmp[i + j] += a[i] * b[j];
}
}
k = alen + blen - ;
for( i = ;i < k; ++i){
if( tmp[i] >= ){
tmp[ i + ] += tmp[i] / ;
tmp[i] = tmp[i] % ;
}
a[i] = tmp[i];
}
a[i] = tmp[i];
if( tmp[k] != )k++;
return k;
} int main(){
char r[LEN + ];
int n, i, j, len, alen, mark, formark, ok;
while( scanf("%s%d",r, &n) == ){
len = strlen(r);
mark = ;
for( i = len - , j = ; i >= ; --i){
if(r[i]=='.'){
mark =i;continue; //记录小数点位置
}
a[j] = b[j++] = r[i]-'';
}
--len;
mark = len - mark;
alen = len;
for( i = ;i < n; i++){
alen = mul( alen,len);
}
for( i = ; i < alen; ++i){
if( a[i] != )break;
}
mark *= n;
formark = i; //记录后缀,如70.10000
ok = ;
for( i = alen-; i >= formark; --i){
if( a[i] == && i >= mark && !ok )continue;
if( i == mark - ) printf(".");
printf("%d", a[i]);
ok = ;
}
for(formark--; formark >= mark; --formark){
printf("");
}
printf("\n");
}
return ;
}
 
 

Poj.Grids 2951 浮点数求高精度幂的更多相关文章

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

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

  2. 【ACM】求高精度幂

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

  3. 求高精度幂(java)

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

  4. poj 1001 求高精度幂

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

  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 3070 && nyoj 148 矩阵快速幂

    poj 3070 && nyoj 148 矩阵快速幂 题目链接 poj: http://poj.org/problem?id=3070 nyoj: http://acm.nyist.n ...

  8. poj 1474 Video Surveillance - 求多边形有没有核

    /* poj 1474 Video Surveillance - 求多边形有没有核 */ #include <stdio.h> #include<math.h> const d ...

  9. poj 1279 Art Gallery - 求多边形核的面积

    /* poj 1279 Art Gallery - 求多边形核的面积 */ #include<stdio.h> #include<math.h> #include <al ...

随机推荐

  1. 何为babel / gulp

    Babel主要用来将新版本的javascript(ES6,ES7)编译为ES5,目前它对于新标准的支持程度甚至高于Chrome浏览器.通过引入预设babel-preset-react,babel还能解 ...

  2. 初学c# -- 学习笔记(八)

    RichTextBox我服了,背景透明.宽度高度自适应.图片背景透明.gif动画等等都tm实现困难无比,搞来搞去,就最后一题做不出来了: RichTextBox不管什么背景,透明背景也好,图片背景也罢 ...

  3. delphi SPCOMM串口控件

    在Delphi7.0中安装Spcomm串口通信控件的方法为:选择Delphi7.0的“Component”菜单,点击“Install Component...”菜单项,然后在弹出的Into exist ...

  4. String类的构造方法详解

    package StringDemo; //String类的构造方法详解 //方法一:String(); //方法二:String(byte[] bytes) //方法三:String (byte[] ...

  5. Spring Framework------>version4.3.5.RELAESE----->Reference Documentation学习心得----->关于spring framework中的beans

    Spring framework中的beans 1.概述 bean其实就是各个类实例化后的对象,即objects spring framework的IOC容器所管理的基本单元就是bean spring ...

  6. 无法连接 MKS: Login(username/password)incorrect

    升级到Vmware Workstation 12之后,客户端能连上虚拟机服务器,但却打不开共享的虚拟机,提示报错"无法连接 MKS: Login(username/password)inco ...

  7. HTML DOM 方法

    一.HMTL DOM对象 --方法和属性 1.1常用的方法. 1.getElementByld( id )方法 --获取带有指定id 的节点( 元素 ) 2.appendChild( node )方法 ...

  8. CSS控制文字,超出部分显示省略号

    http://www.daqianduan.com/6179.html <p style="width: 300px;overflow: hidden;white-space: now ...

  9. textarea格式显示问题

    在 textarea 表单标签中, 当保存有换行的样式时,一般的方法有: 注:这里的info 为要显示的内容: 一.保存后在textarea 表单标签中显示时: info.replace(/\n/g, ...

  10. Eclipse 在ubuntu桌面显示快捷启动以及解决Eclipse 在ubuntu中点击菜单栏不起作用的原因.

    要在Eclipse中设置好之后,可以通过如下方式在周末显示快捷启动以及解决Eclipse在ubuntu高版本中点击菜单栏项不显示列表的问题 在usr/share/app-install/desktop ...