POJ 1001 Exponentiation解题报告
来源:互联网 发布:java 泛型方法 调用 编辑:程序博客网 时间:2024/05/29 02:05
Exponentiation
Time Limit: 500MS Memory Limit: 10000KTotal Submissions: 127985 Accepted: 31266
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 0 < n <= 25.
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 0 < n <= 25.
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 R^n. Leading zeros should be suppressed in the output. Insignificant trailing zeros must not be printed. Don't print the decimal point if the result is an integer.
Sample Input
95.123 120.4321 205.1234 156.7592 998.999 101.0100 12
Sample Output
548815620517731830194541.899025343415715973535967221869852721.0000000514855464107695612199451127676715483848176020072635120383542976301346240143992025569.92857370126648804114665499331870370751166629547672049395302429448126.76412102161816443020690903717327667290429072743629540498.1075960194566517745610440100011.126825030131969720661201
解题思路:解题的关键是大整数的乘法以及0和小数点的处理。
/**project:1001*version:AC+大整数乘法*author:骨灰在飞扬*Memory:236K*Time:16MS*note:*date:2014/2/10*/#include <iostream>#include <string>#include <algorithm>#include <fstream>using namespace std;const int MAX_LEN = 1000;int ia[MAX_LEN];string subF(string str1, string str2){ int i,j; string result; memset(ia,0,sizeof(ia)); // 暂存乘法运算的结果 reverse(str1.begin(), str1.end()); // 倒置 reverse(str2.begin(), str2.end()); int point1, point2,point; // 小数位数 point1 = str1.find('.'); point2 = str2.find('.'); if(point1 != string::npos) // 如果为小数,则将小数点删除 str1.erase(str1.begin()+point1); else point1 = 0; if(point2 != string::npos) str2.erase(str2.begin()+point2); else point2 = 0; point1 > point2 ? point = point1 : point = point2; // point保存最大的小数位数 int len1 = str1.size(); int len2 = str2.size(); for(i = 0; i < len1; i++) // 乘法运算 for(j = 0; j < len2; j++) ia[i+j] += (str1[i]-'0')*(str2[j]-'0'); int len; // 乘积的长度 for(i = 0; i < len1+len2; i++) // 进位处理 { if(ia[i] >= 10) { ia[i+1] += (ia[i]/10); ia[i] %= 10; } } if(ia[len1+len2-1] > 0) len = len1+len2; else len = len1+len2-1; for(i = len-1; i >= 0; i--) result += char(ia[i]+'0'); if(point > 0) // 插入小数点 { result.insert(result.end()-point1-point2,'.'); for(i = result.size()-1; i >= 0; i--) // 去除小数点后的后置0 { if(result[i] == '0') result.erase(result.begin()+i); else if(result[i] == '.') { result.erase(result.begin()+i); break; } else break; } while( (*result.begin()) == '0' )// 去除小数点前的前置0 result.erase(result.begin()); } return result;}int main(){ //ifstream cin("E:\\vcpp\\test.txt"); string str1; int n; while(cin >> str1 >> n) { string str2("1"); while(n--) { str2 = subF(str1, str2); } cout << str2 << endl; } system("pause"); return 0;}
0 0
- POJ 1001 Exponentiation解题报告
- POJ 1001 解题报告 Exponentiation
- POJ 1001 Exponentiation解题报告
- POJ 1001 Exponentiation [解题报告] Java
- POJ解题报告——1001 Exponentiation
- POJ 1001 Exponentiation C++解题报告 JAVA解题报告
- poj1001:1001:Exponentiation解题报告
- pku 1001 高精度 Exponentiation 解题报告
- POJ1001 Exponentiation (解题报告)
- poj1001 Exponentiation 解题报告
- POJ 1001Exponentiation解题报告——求高精度幂——【PKU ACM】
- POJ——1001 Exponentiation 解题思路
- HDU 1063 Exponentiation解题报告
- UVa 748 Exponentiation解题报告
- hdoj--1063 Exponentiation 解题报告
- poj 1001解题报告
- POJ 1001解题报告
- POJ 1001 解题报告
- 从零开始学习OpenGL ES之七 – 变换和矩阵
- 友元函数
- android NDK底层调用java方法
- OpenGL: Glut实现选取
- SetOnwer
- POJ 1001 Exponentiation解题报告
- Oracle 客户端配置后,同时再装服务器端出现的无法同时链接远程服务器和本地的问题
- java设计模式-代理模式
- MFC窗口中的SetOnwer等。
- C++ 类的多重继承
- @Component @Service @Controller @Repository注解使用
- ZXR10 1800路由器配置
- 搭建Samba服务
- JNI本地文件添加打印输出到LOGCAT