Poj.Grids 2951 浮点数求高精度幂
- 总时间限制:
 - 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 浮点数求高精度幂的更多相关文章
- poj 1001 求高精度幂(Java, BigDecimal, pow, hasNext, stripTrailingZeros, toPlainString)
		
求高精度幂 Time Limit: 500MS Memory Limit: 10000K Total Submissions: 180325 Accepted: 43460 Descripti ...
 - 【ACM】求高精度幂
		
题目来源:http://poj.org/problem?id=1001&lang=zh-CN 求高精度幂 Time Limit: 500MS Memory Limit: 10000K To ...
 - 求高精度幂(java)
		
求高精度幂 时间限制:3000 ms | 内存限制:65535 KB 难度:2 描述 对数值很大.精度很高的数进行高精度计算是一类十分常见的问题.比如,对国债进行计算就是属于这类问题. 现在要 ...
 - poj 1001  求高精度幂
		
本题的测试用例十分刁钻,必须要考虑到很多的细节问题,在这里给出一组测试用例及运行结果: 95.123 12 548815620517731830194541.899025343415715973535 ...
 - Exponentiation(求高精度幂)
		
Exponentiation Time Limit: 500MS Memory Limit: 10000K Total Submissions: 175340 Accepted: 42341 ...
 - 求高精度幂(poj1001)
		
Description Problems involving the computation of exact values of very large magnitude and precision ...
 - poj 3070 && nyoj 148 矩阵快速幂
		
poj 3070 && nyoj 148 矩阵快速幂 题目链接 poj: http://poj.org/problem?id=3070 nyoj: http://acm.nyist.n ...
 - poj 1474 Video Surveillance - 求多边形有没有核
		
/* poj 1474 Video Surveillance - 求多边形有没有核 */ #include <stdio.h> #include<math.h> const d ...
 - poj 1279 Art Gallery - 求多边形核的面积
		
/* poj 1279 Art Gallery - 求多边形核的面积 */ #include<stdio.h> #include<math.h> #include <al ...
 
随机推荐
- 使用SeasLog打造PHP项目中的高性能日志组件(一)
			
云智慧(北京)科技有限公司 高驰涛 什么是SeasLog SeasLog是一个C语言编写的PHP扩展,提供一组规范标准的功能函数,在PHP项目中方便.规范.高效地写日志,以及快速地读取和查询日志. 为 ...
 - MFC对话框中显示BMP,JPG图片
			
//************************************ // 方法说明: 显示JPG和GIF.BMP图片 // 参数说明: CDC * pDC 设 ...
 - 触摸屏测试:Tslib
			
触摸屏测试:Tslib(配置了一天,心累) 总结:网上有许多关于tslib的步骤/错误总结,所以这里只是提几个我觉得比较棘手的问题: 1,我明明给arm-linux-gcc配置了环境变量,为什么还是提 ...
 - arduino编程语言Wiring参考手册API
			
对Arduino的编程是利用 Arduino编程语言 (基于 Wiring)和Arduino开发环境(based on Processing)来实现的. 通过编程,Arduino可以实现很多种功能. ...
 - 把vim当做golang的IDE
			
开始决定丢弃鼠标,所以准备用vim了. 那么在vim里面如何搭建golang环境呢? git盛行之下,搭建vim环境是如此简单. 而且vim搭建好了之后,基本上跟IDE没有差别. 高亮.自动补全.自动 ...
 - 查看Oracle中是否有锁表的sql
			
1.查看是否有锁表的sql 代码如下: select 'blocker('||lb.sid||':'||sb.username||')-sql:'|| qb.sql_text blockers, 'w ...
 - Only the sqlmigrate and sqlflush commands can be used when an app has migrations.
			
samcao@samcao-Lenovo-IdeaPad-Y470:~/caodjango/caossh$ python manage.py sqlall getssh System check id ...
 - 「脑洞」图片转HTML(支持动画)
			
也许是受到很久以前看到的这玩意儿的原因:The Shapes of CSS 现在开脑洞写了个自动转换,顺便支持了动画……嗯,纯 CSS (:з」∠) 主要步骤就是用 Python 读图片,然后把像素全 ...
 - c# - catch(Exception ex) 会丢掉StackTrace 是怎么回事?
			
原本这篇文章就想写写StackTrace怎么会丢的问题, 但现在的内容变成了讨论怎么处理Exception的问题. 该不该用try catch, 什么时候用?也困扰了我很久, 好像随便写写就可以, 但 ...
 - spring知识大全(4)
			
5 Spring对事务的支持 一.AOP事务的含义: 事务当作一个切面,动态地织入到目标对象,形成一个代理对象. 二.Spring的事务机制 Spring支持声明式事务. Spring使用事务服务代理 ...