hdu_1063,poj_1001_Exponentiation(大数,高精度) nyoj_155_求高精度幂
来源:互联网 发布:杭州萤石网络 点评 编辑:程序博客网 时间:2024/04/29 03:16
Exponentiation
Time Limit: 500MS Memory Limit: 10000KTotal Submissions: 121666 Accepted: 29731
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
Hint
If you don't know how to determine wheather encounted the end of input:
s is a string and n is an integer
s is a string and n is an integer
C++while(cin>>s>>n){...}cwhile(scanf("%s%d",s,&n)==2) //to see if the scanf read in as many items as you want/*while(scanf(%s%d",s,&n)!=EOF) //this also work */{...}
Source
East Central North America 1988
import java.math.BigDecimal;import java.util.Scanner;public class nyoj_155_求高精度幂 {//Accepted 3360K 188MS Java 424B 2013-08-30 21:25:53 public static void main(String[] args) {Scanner sc =new Scanner(System.in);while(sc.hasNext()){BigDecimal a = sc.nextBigDecimal();int b =sc.nextInt();a=a.pow(b);String s=a.stripTrailingZeros().toPlainString();if(s.startsWith("0."))s=s.substring(1);System.out.println(s);}}}
说明:
1、stripTrailingZeros() ,返回类型为BigDecimal的小于此数的但除去尾部的0的数值。
2、toPlainString(),返回BigDecimal类型的String类型字符串。
3、startsWith(),确定此实例的开头是否与指定的字符串匹配。
4、substring(),返回一个新的字符串,它是此字符串的一个子字符串。该子字符串始于指定索引处的字符,一直到此字符串末尾。
- hdu_1063,poj_1001_Exponentiation(大数,高精度) nyoj_155_求高精度幂
- 高精度大数求幂
- 【大数问题】求高精度幂
- ACM 大数 求高精度幂
- NYOJ 155 求高精度幂【大数问题】
- nyoj 155 求高精度幂 【大数】
- 高精度问题之大数求幂
- 大数乘方 求高精度幂 NOYJ155
- [POJ](1001)求高精度幂 ---大数
- 大数,高精度计算---高精度幂次
- 8、大数,高精度计算---高精度幂次
- POJ 1001-Exponentiation(NYOJ 155 求高精度幂):大数问题
- POJ-1001 求高精度幂-大数乘法系列
- 求高精度幂
- 高精度求幂运算
- 求高精度幂
- 求高精度幂
- POJ1001 求高精度幂
- apache vhost的配置
- mysql性能优化小技巧
- Stanford Machine Learning -- 第十讲 大规模学习
- error while loading shared libraries
- 图解 linux log系统
- hdu_1063,poj_1001_Exponentiation(大数,高精度) nyoj_155_求高精度幂
- 刨根问底
- 大公司还是创业公司,你怎么选择?
- 如果给定一个数组arr[0,...N-1],要求找出相邻两个数的最大差值
- 在二元树中找出和为某一值的所有路径(树)
- 《C++标准程序库》——STL迭代器
- .s 生成 .o
- FTP命令详解
- 2.2 栈的实现