poj1001 Exponentiation

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.

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 12  0.4321 20  5.1234 15  6.7592  9  98.999 10  1.0100 12  

Sample Output

548815620517731830194541.899025343415715973535967221869852721
.00000005148554641076956121994511276767154838481760200726351203835429763013462401
43992025569.928573701266488041146654993318703707511666295476720493953024
29448126.764121021618164430206909037173276672
90429072743629540498.107596019456651774561044010001
1.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

import java.util.Scanner;
import java.math.*;
public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            BigDecimal bd = new BigDecimal(sc.next());
            BigDecimal result = bd.pow(sc.nextInt());
            String s = result.stripTrailingZeros().toPlainString();
            if(s.startsWith("0"))
                s=s.substring(1);
            System.out.println(s);
        }
    }
}

poj1001 Exponentiation,布布扣,bubuko.com

时间: 2024-10-23 08:50:28

poj1001 Exponentiation的相关文章

poj1001 Exponentiation【java大数】

Exponentiation Time Limit: 500MS   Memory Limit: 10000K Total Submissions: 183034   Accepted: 44062 Description Problems involving the computation of exact values of very large magnitude and precision are common. For example, the computation of the n

POJ 1001 解题报告 高精度大整数乘法模版

题目是POJ1001 Exponentiation  虽然是小数的幂 最终还是转化为大整数的乘法 这道题要考虑的边界情况比较多 做这道题的时候,我分析了 网上的两个解题报告,发现都有错误,说明OJ对于错误的判断还不够严厉. 对边界情况的讨论其实应该是思维严密的表现,当然这并不能表明我写的一点错误都没有,只是多多分析一下还是很有好处的. #include <iostream> #include <fstream> #include <string> #include &l

【poj1001】 Exponentiation

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<iost

Exponentiation POJ-1001

http://poj.org/problem?id=1001 1 //10000000 100000 2 3 #include<iostream> 4 #include<cstring> 5 using namespace std; 6 7 char ts[7],tts[7]; //用于处理输入,删去点,签到0,点后0,统计小数点后数的个数保存至origu 8 short orig[7],ans[2500],t_ans[2500]; // t_ans存乘法运算的中间过程 9 int

poj1001(高精度)

Exponentiation Time Limit: 500MS   Memory Limit: 10000K Total Submissions: 132438   Accepted: 32334 Description Problems involving the computation of exact values of very large magnitude and precision are common. For example, the computation of the n

hdu 1063 Exponentiation

http://acm.hdu.edu.cn/showproblem.php?pid=1063 1 import java.math.BigDecimal; 2 import java.util.*; 3 public class Main { 4 public static void main(String []args) 5 { 6 Scanner cin=new Scanner(System.in); 7 BigDecimal r,mutil; 8 String ans; 9 int n;

POJ 1001 Exponentiation

Exponentiation Time Limit: 500MS   Memory Limit: 10000K Total Submissions: 171995   Accepted: 41641 Description Problems involving the computation of exact values of very large magnitude and precision are common. For example, the computation of the n

HDU Exponentiation 1063 Java大数题解

Exponentiation Time Limit: 1000/500 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 6973    Accepted Submission(s): 1975 Problem Description Problems involving the computation of exact values of very large magnitude

poj1001(高精度乘法)

1.题目表述 Exponentiation Time Limit: 500MS   Memory Limit: 10000K Total Submissions: 135893   Accepted: 33256 Description Problems involving the computation of exact values of very large magnitude and precision are common. For example, the computation o