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 ...
随机推荐
- html初学者了解的笔记02
一.Html简介 HTML 是一种标记语言 忽略大小写,语法宽松 使用 HTML 标记和元素,可以: 控制页面和内容的外观 发布联机文档 使用 HTML 文档中插入的链接检索联机信息 创建联机表单,收 ...
- Ruby-模块和类
首先看下他们的关系 irb(main):100:0> String.class => Class irb(main):101:0> String.class.superclass ...
- c++接口实现与分离(转载)
原文地址:http://www.360doc.com/content/13/0218/10/8363527_266294787.shtml 良好的设计应该只暴露接口给用户,所有的实现细节对用户来说应该 ...
- C#获取本机公网IP
/// <summary> /// 获取本机公网IP /// </summary> /// <returns></returns> public sta ...
- IE11部分图片无法显示的兼容办法
问题描述:写的网页在浏览器中测试兼容问题,FF,Chrome,Edge都完美兼容(包括Edge中的仿真),但是在IE11中却无法显示部分图片,并且报:DOM7009: 无法解码 URL 处的图像 错误 ...
- laravel(三):larave基本使用
1.基本视图显示 前文已经介绍如何创建控制器.动作和视图,下面我们来创建一些更实质的功能. 在此之前我们需要修改一些配置: app/config/app.php 文件中的 debug 选项设置为 tr ...
- linux下添加链接与删除链接(ln命令的用法)
添加链接使用ln命令用法:#ln --help用法:ln [选项]... 目标 [链接名]或:ln [选项]... 目标... 目录或:ln [选项]... --target-directory=目录 ...
- mysql,实现数据库检索结果添加自增的序号
select t2.rowno from( select (@rownum:=@rownum+1) as rowno, t1.id from news t1 ,(select (@rownum ...
- iis7下配置php出现404.17错误的解决办法
服务器上建有几个PHP站点,都在正常运行.今天又新建了一个PHP站点,处理程序模块配置的和其他几个都一样,但就是跑不起来,一直提示404.17错误,重启服务器也不行. 最后实在没办法了,就把正常运行站 ...
- git & scp
git & scp command : git & scp git git 提交 git checkout/pull =====[在提交前校验远程是否有冲突] git add [< ...