【poj1001】 Exponentiation
来源:互联网 发布:淘宝手机端详情编辑 编辑:程序博客网 时间:2024/05/20 13:06
http://poj.org/problem?id=1001 (题目链接)
题意:求实数R的n次方,要求高精度。
Solution
SB题Wa了一下午,直接蒯题解。
高精度,小数点以及去前导后导零很麻烦,而且题目数据很刁钻。
注意几个数据:
00.000 20
0
000.10 20
.00000000000000000001
.10000 25
.0000000000000000000000001
1 0
1
如果还要数据大话,大牛博客上有。
代码:
#include<iostream>using namespace std;char str[10];int n, dot;int res[999999], a[999999], b[999999];int len, lena, lenb;void mul(){ int i, j; memset(res, 0, sizeof(res)); for (i=1; i<=lena; i++) { for (j=1; j<=lenb; j++) { res[i+j-1] += a[i] * b[j]; if (res[i+j-1]>9) { res[i+j] += res[i+j-1] / 10; res[i+j-1] %= 10; } } } if (res[lena+lenb-1]>9) { res[lena+lenb] += res[lena+lenb-1] / 10; res[lena+lenb-1] %= 10; } lena = lena + lenb; for (i=1; i<=lena; i++) a[i] = res[i];}int main(){ int i, j, up, down; while (scanf("%s %d", str, &n)!=EOF) { dot = -1; for (i=5, j=1; i>=0; i--) { if (str[i]!='.') a[j] = b[j++] = str[i] - '0'; else dot = i; } if (dot==-1) lena = lenb = 6; else lena = lenb = 5; for (i=1; i<n; i++) mul(); if (dot==-1) { for (i=lena; i>=1; i--) printf("%d", a[i]); printf("\n"); } else { dot = 5 - dot; dot *= n; for (i=1; i<=lena; i++) { if (a[i]!=0) { down = i; break; } } for (j=lena; j>=1; j--) { if (a[j]!=0) { up = j; break; } } i = up; if (up<dot) i = dot; j = down; if (j>dot) j = dot + 1; for (; i>=j; i--) { if (i==dot) printf("."); printf("%d", a[i]); } printf("\n"); } } return 0;}
0 0
- POJ1001 Exponentiation
- POJ1001 Exponentiation
- POJ1001 Exponentiation
- POJ1001 Exponentiation
- POJ1001:Exponentiation
- 【poj1001】 Exponentiation
- POJ1001 Exponentiation
- POJ1001 Exponentiation
- poj1001 Exponentiation
- poj1001——Exponentiation
- poj1001 Exponentiation 小数幂
- POJ1001 Exponentiation 高精度乘法
- POJ1001 Exponentiation 高精度
- POJ1001 Exponentiation,高精度乘法
- POJ1001 Exponentiation (解题报告)
- POJ1001·Exponentiation
- poj1001 Exponentiation --高精度
- poj1001 Exponentiation 解题报告
- Android自动化测试--monkey的使用
- 淘宝搜索排序
- OpenGLes学习之路(一)————opengles内部执行顺序(1)
- 电话验证码通道
- 剑指offer——栈与队列之间的相互实现
- 【poj1001】 Exponentiation
- 如何使用Sublime的插件(以HexViewer为例)
- MyBatis Generator 详解
- 从context分析到脱离三方app的dialog
- 剑指Offer:字符串的排列
- 每日一个window命令(每日一个linux命令的姐妹篇)
- Java中导入、导出Excel
- iOS利用Block传值
- 自己实现文件拷贝