UVA - 748 Exponentiation
来源:互联网 发布:淘宝网开店费用 编辑:程序博客网 时间:2024/05/16 14:22
题目大意:求 R 的 n 次方
解题思路:循环高精度乘法
#include<iostream>#include<cstdio>#include<cstdlib>#include<cstring>#include<cmath>#include<ctype.h>using namespace std;char R[10];int r[10];int ans[1000];int map[1000][1000];int main() { int n; while (scanf("%s%d", R, &n) != EOF) { memset (ans, 0, sizeof(ans)); int p, len = strlen(R) - 1; for (int i = len, j = 0; i >= 0; i--,j++) { if (R[i] == '.') { p = j; j--; continue;} r[j] = R[i] - '0'; ans[j] = r[j]; } p *= n; int tot = len; n--; while (n--) { memset (map, 0, sizeof(map)); for (int i = 0; i < len; i++) for (int j = 0; j < tot; j++) { map[i][i+j] += ans[j] * r[i]; if (map[i][i+j] > 9) { map[i][i+j+1] += map[i][i+j]/10; map[i][i+j] %= 10; } } tot += len; memset (ans, 0, sizeof(ans)); for (int i = 0; i < tot; i++) for (int j = 0; j < len; j++) { ans[i] += map[j][i]; if (ans[i] > 9) { ans[i+1]++; ans[i] -= 10; } } } while (ans[tot] == 0) { if (tot == p-1) break; tot--; } while (tot != -1) { int tag = 1, flag = 0; if (ans[tot] == 0) { flag = 1; for (int i = tot; i >= 0; i--) if(ans[i] != 0) tag = 0; } if (flag && tag) break; if (tot == p-1) printf("."); printf("%d", ans[tot--]); } printf("\n"); } return 0;}
0 0
- UVa 748 Exponentiation
- UVa OJ 748-Exponentiation
- uva 748 - Exponentiation
- UVA 试题 748 - Exponentiation
- UVa 748 - Exponentiation
- UVa 748 - Exponentiation
- UVa 748Exponentiation
- uva 748Exponentiation
- UVA 748 Exponentiation
- UVA 748 - Exponentiation
- UVA 748 Exponentiation
- UVa 748 - Exponentiation
- uva 748 Exponentiation
- UVa 748 - Exponentiation
- UVa:748 - Exponentiation
- UVa 748 - Exponentiation
- UVa-748-Exponentiation
- UVA - 748 Exponentiation
- USB WIFI 腾达811M无线网卡 -RT5370移植
- 多项式求和 hd 2011
- neural-networks-and-deep-learning mnist_average_darkness.py
- Memory leak in Windows 8.1 with Killer E2200 and Windows Network Data Usage Monitoring
- UVA-621 Secret Research
- UVA - 748 Exponentiation
- UVA11988 模拟题,水
- UVA - 10494 If We Were a Child Again
- LeetCode-100:Same Tree
- 暑期总结——网络流
- CentOS 6.5命令行安装MATLAB2013
- javascript的window对象
- 刘同学请保重身体
- linux误挂载到根目录出现问题