Uva 748 Exponentiation (高精度幂运算)
来源:互联网 发布:php文件上传漏洞 编辑:程序博客网 时间:2024/06/02 04:15
Description
Problems involving the computation of exact values of very large magnitude and precision are common. For example, the computation of the national debt is a taxing experience for many computer systems.
This problem requires that you write a program to compute the exact value of Rn where R is a real number ( 0.0 < R < 99.999) and n is an integer such that .
Input
The input will consist of a set of pairs of values for R and n. The R value will occupy columns 1 through 6, and the n value will be in columns 8 and 9.
Output
The output will consist of one line for each line of input giving the exact value of Rn. Leading zeros and insignificant trailing zeros should be suppressed in the output.
Sample Input
95.123 120.4321 205.1234 156.7592 998.999 101.0100 12
Sample Output
548815620517731830194541.899025343415715973535967221869852721.0000000514855464107695612199451127676715483848176020072635120383542976301346240143992025569.92857370126648804114665499331870370751166629547672049395302429448126.76412102161816443020690903717327667290429072743629540498.1075960194566517745610440100011.126825030131969720661201
问题描述:
这题主要是一道高精度的的大数幂运算问题
题目要求:
输入两个数浮点数R,和整数n,求R^n
其中0.0 < R < 99.999
题目解析:
这题题目的时间要求比较长3000MS,所以可以用大数相乘,再循环n次,得出的大数没有小数点。
所以需要先记录下R小数点的位置,小数点之后的长度*n,就是小数点的位置。
#include<string>#include<iostream>#include<stdio.h>#include<string.h>using namespace std;const int MAX = 1000;void getNum(int num[],string str) {int len = str.size();for(int i=0;i<len;i++) {num[len-1-i]=str[i]-'0';}}void multiSolve(int num1[],int num2[],int sum[]) {for(int i=0;i<MAX;i++)for(int j=0;j<MAX;j++) {sum[i+j] += num1[i]*num2[j];}for(int i=0;i<MAX*2-1;i++) {sum[i+1] += sum[i]/10;sum[i] = sum[i]%10;}}string multi(string str1,string str2) {int num1[MAX],num2[MAX],sum[MAX*2];memset(num1,0,sizeof(num1));memset(num2,0,sizeof(num2));memset(sum,0,sizeof(sum));getNum(num1,str1);getNum(num2,str2);multiSolve(num1,num2,sum);int count = MAX*2 - 1;while(sum[count]==0) {count--;}string strSum;char dig;for(int i=count ;i >= 0; i--) {dig=sum[i]+'0';strSum.push_back(dig);}return strSum;}string power(string str,int pow){int after;int doe;int pos = str.find('.');int lenx;int len_str = str.size();if(pos != string::npos) {str.erase(pos,1);lenx=str.size();after = lenx - 1;doe = len_str - pos -1;}else {doe=0;}string sum="1";for(int i=0; i<pow ; i++) {sum=multi(sum,str);}int len = sum.size();string result;if(str[0] >= '1') {for(int i=0 ; i<len ;i++) {result.push_back(sum[i]);if( i== len - pow*doe -1 && doe != 0 ) {result.push_back('.');}}}else {result.push_back('.');for(int i=0;i< pow*after-len;i++) {result.push_back('0');}result += sum;}return result;}int main(){string str;string result;int pow;while(cin>>str>>pow) {getchar();result = power(str,pow);int len = result.size();for(int i=len-1;i >= 0;i--) {if(result[i] == '0')result.erase(i,1);elsebreak;}cout<<result<<endl;}return 0;}
- Uva 748 Exponentiation (高精度幂运算)
- UVA - 748 Exponentiation 高精度
- uva 748 Exponentiation 浮点数乘方运算 高精度水题
- UVA 748 Exponentiation 高精度乘法
- uva 748 Exponentiation(高精度实数乘法)
- UVA 748 (暑假-高精度-C-Exponentiation)
- UVa 748 / POJ 1001 Exponentiation (浮点高精度求幂&正则表达式的应用)
- poj 1001 uva 748 Exponentiation(高精度小数乘法)
- ACM 1001 Exponentiation 高精度幂浮点型的运算
- poj1001-Exponentiation(高精度幂)
- POJ1001 Exponentiation(高精度幂)
- POJ 1001 Exponentiation - 高精度高位数运算
- poj 1001 Exponentiation(高精度运算)
- UVa 748 Exponentiation
- UVa OJ 748-Exponentiation
- uva 748 - Exponentiation
- UVA 试题 748 - Exponentiation
- UVa 748 - Exponentiation
- js方法判断ie浏览器版本
- srvctl start instance -d devdb -i devdb1(测)
- 工业超纯水机:工业纯水设备的工艺特点介绍
- 求救,flash cookie 视频节目都无法观看。没有办法了吗,只能任人宰割??
- 面试
- Uva 748 Exponentiation (高精度幂运算)
- subSequence,SubString,split总结
- Tomcat性能调优方案
- C++学习第4章 复合类型
- linux切换图形界面和命令行
- Xcode6中Swift没有智能提示和自动补全功能
- C语言中的typeof关键字
- 【原创】ASP.NET 安全认证(三)—— 用Form 表单认证实现单点登录(Single Sign On)(转)
- Codeforces Round #FF (Div. 2) A.DYZ Loves Hash