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 ...
随机推荐
- shll 变量
name=zhagnsan age=11 echo $ name $age 赋值号两边没有任何空格.当想取shell变量的值时,需要在变量名前加上$字符,当所赋的值中间含有空格时,要加上引号 函数: ...
- 关于16年2月14日以后上传AppStore出现:Missing iOS Distribution signing identity for...的问题
2016年2月14日以后打包上传AppStore会发现出现如下的问题: 导致问题的原因是:下边这个证书过期了 以下是苹果官方给出的回应: Thanks for bringing this to the ...
- 轻型的ORM类Dapper
Dapper是一个轻型的ORM类.代码就一个SqlMapper.cs文件,主要是IDbConnection的扩展方法,编译后就40K的一个很小的dll.官方站点http://code.google.c ...
- 【好文要转】HTTP图解(大牛必经之路)
http://www.cnblogs.com/aylin/p/6221436.html
- NGUI BUG /各种坑
以下为:NGUI3.6具体使用过程中碰到的 各种BUG /各种坑 备忘 1.UIToggle 使用UIToggle组件实现多个tab标签互斥,如果是在代码中动态的设置显示某个tab标签对应的内容,则需 ...
- C# Winform学习--- 实现石头剪刀布的游戏
本文使用winform实现简单的石头剪刀布的游戏,主要实现,电脑随机出拳,玩家手动点击出拳:实现简易背景图片3秒切换:简易统计信息. 1.效果图 2.实现代码 新建一个windows窗体程序,用数字1 ...
- SpringMVC+Freemarker+JSTL支持
前提: 网页编程中,我的思路是,通用的模块不仅仅只有后台代码,前端页面也可以独立为模块. 这个和asp.net中的UserController很像 比如有个人员基本信息的展示界面,需要在多个界面中嵌入 ...
- LVS_DR模式构建配置
一.环境准备 lvs负载均衡器 系统:centos6.8 ip:192.168.2.203 vip:192.168.2.17 web服务器RS1 系统:centos6.8 ip:192.168.2.2 ...
- 小米Git
这个题目的意思其实就是要分别从根节点开始遍历(dfs)到给定的两个点,然后从得出的路径中获取最早相同的点即为结果. class Solution { public: /** * 返回git树上两点 ...
- 使用kindeditor文本编辑器
aspx中代码: <%@ Page Language="C#" ValidateRequest="false" AutoEventWireup=" ...