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

大数的题目使用Java就变得其简单无比。

主要就一句代码:

String ans = a.pow(b).stripTrailingZeros().toPlainString();

去零和转换为纯字符串输出。

这使用C++要数十行代码。

对照C++解法:http://blog.csdn.net/kenden23/article/details/23997827

相比之下。java就成了水题了。学不到什么东西。

import java.math.BigDecimal;
import java.util.*; public class Main
{
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
while (scan.hasNext())
{
BigDecimal a = scan.nextBigDecimal();
int b = scan.nextInt();
String ans = a.pow(b).stripTrailingZeros().toPlainString();
if (ans.startsWith("0")) ans = ans.substring(1);
System.out.println(ans);
}
scan.close();
}
}

HDU Exponentiation 1063 Java大数题解的更多相关文章

  1. hdu 1042 N! java大数及判断文件末尾

    N! Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submi ...

  2. poj1001 Exponentiation【java大数】

    Exponentiation Time Limit: 500MS   Memory Limit: 10000K Total Submissions: 183034   Accepted: 44062 ...

  3. [ACM_数学] 大菲波数 (hdu oj 1715 ,java 大数)

    大菲波数 Problem Description Fibonacci数列,定义如下:f(1)=f(2)=1f(n)=f(n-1)+f(n-2) n>=3.计算第n项Fibonacci数值.   ...

  4. hdu 4043 FXTZ II [ 概率 + Java大数]

    传送门 FXTZ II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  5. 【百度之星】【java大数+C++做法】hdu 6719 Strassen

    代码:递归搜索一下.java大数做法 import java.util.*; import java.math.*; import java.security.MessageDigest; publi ...

  6. 【Java】-BigInteger大数类的使用【超强Java大数模板 总结】

    Scanner cin = new Scanner(new BufferedInputStream(System.in)); 这样定义Scanner类的对象读入数据可能会快一些! 参考这个博客继续补充 ...

  7. 多校第五场 归并排序+暴力矩阵乘+模拟+java大数&amp;记忆化递归

    HDU 4911 Inversion 考点:归并排序 思路:这题呀比赛的时候忘了知道能够用归并排序算出逆序数,可是忘了归并排序的实质了.然后不会做-- 由于看到题上说是相邻的两个数才干交换的时候.感觉 ...

  8. Java 大数、高精度模板

    介绍: java中用于操作大数的类主要有两个,一个是BigInteger,代表大整数类用于对大整数进行操作,另一个是BigDecimal,代表高精度类,用于对比较大或精度比较高的浮点型数据进行操作.因 ...

  9. hdu1133 Buy the Ticket (卡兰特数应用+java大数)

    题目链接:http://acm.hdu.edu.cn/showproblem.php? pid=1133 [题意] 电影票50块一张 有m个人手里正好有50块,n个人手里正好有100块,售票厅開始没有 ...

随机推荐

  1. Spring摘记

    spring工作机制及为什么要用? 1.spring mvc请所有的请求都提交给DispatcherServlet,它会委托应用系统的其他模块负责负责对请求进行真正的处理工作.2.Dispatcher ...

  2. 转:JavaScript函数式编程(一)

    转:JavaScript函数式编程(一) 一.引言 说到函数式编程,大家可能第一印象都是学院派的那些晦涩难懂的代码,充满了一大堆抽象的不知所云的符号,似乎只有大学里的计算机教授才会使用这些东西.在曾经 ...

  3. qt介绍

    http://www.oschina.net/p/qt Qt 是一个跨平台的C++图形用户界面应用程序框架.它提供给开发者建立图形用户界面所需的功能,广泛用于开发GUI程序,也可用于开发非GUI程序. ...

  4. Android混淆、反编译以及反破解的简单回顾

    =========================================================================虽然反编译很简单,也没下面说的那么复杂,不过还是转了过 ...

  5. Linux下利用fork()创建子进程并使父进程等待子进程结束

    int status; pid_t t = fork(); if(t){     waitpid(t, &status, 0); }else{     system("vi temp ...

  6. Cocoa 之 Core Data(2)- 代码示例

    前面详 细讲解了 Core Data 的框架以及设计的类,下面我们来讲解一个完全手动编写代码 使用这些类的示例,这个例子来自 苹果官方示例.在这个例子里面,我们打算做这样一件事 情:记录程序运行记录( ...

  7. Redmine email配置

    很简单,先安装sendmail apt-get install sendmail 然后在redmine目录的配置文件conf/configuration.yml中取消几行注释: # ==== Send ...

  8. 设计模式之二十四:訪问者模式(Visitor)

    訪问者模式: 定义了一个作用于一个类的一些操作,訪问者模式同意在不改变类的前提下添加一些操作. Represent an operation to be performed on the elemen ...

  9. C-Free 您不能使用调试解决方案

    什么时候C-Free 当您调试 找不到gdb.exe解决方案 http://www.programarts.com/ C-Free 官方网站 下载Mingw或者其他编译器 版权声明:本文博主原创文章. ...

  10. Haffman算法(C++)

    Huffman编码,C++实现,只是为了说明大致的思路,还有很多不完美之处,比如在输入数据超出限制等条件下会出现错误. #include<iostream> #include<str ...