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. xml 解析 Xstream

    1.概述 json 解析可以使用gson包解为现成的对象,那么xml可以不可以用现成的包解析成java的对象呢? 带着这个问题,查询了一些材料找到了Xstream解析方法,确实可以完成这种思考,只是实 ...

  2. delphi 读网页线程TReadHtmlThread

    读网页,通常是一个耗时操作.故把读网页放入线程是显得比较重要了. 本例用改进后的 TIdhttpEx 加上线程来实现读网页. 它的父类TSimpleThread 在此 本例程源码在此 源码中包含了所有 ...

  3. 在esx上 docker的网络桥接

    docker:/root# docker run -itd --net=none --name zjtest8_haproxy 192.168.32.150:5000/zjzc_centos6.5_m ...

  4. perl 一个简单的面向对象的例子

    <pre name="code" class="python">[root@wx03 wx]# cat x1.pm package x1; use ...

  5. centos 6.5安装GitLab全过程和问题记录

    GitLab,是一个使用 Ruby on Rails 开发的开源应用程序,与Github类似,能够浏览源代码,管理缺陷和注释,非常适合在团队内部使用. 官方只提供了Debian/Ubuntu系统下的安 ...

  6. hdu 3934 Summer holiday(凸包最大内接三角形)

    求n个点能组成的最大三角形,一发旋转卡壳模板题... #include<algorithm> #include<iostream> #include<cstring> ...

  7. Triangle LOVE(拓扑排序)

    Triangle LOVE Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/65536K (Java/Other) Total ...

  8. 系统学习Linux的11点建议

    一.从基础开始 常常有些朋友在 Linux 论坛问一些问题,不过,其中大多数的问题都是很基础的.例如为什么我使用一个命令的时候,系统告诉我找不到该目录,我要如何限制使用者的权限等问题,这些问题其实都不 ...

  9. 两种Makefile

    .PHONY:clean CC=g++ CFLAGS=-Wall -g BIN=test_queue OBJS=Queue.o test_main.o $(BIN):$(OBJS) $(CC) $(C ...

  10. 在sql数据库变量中保存单引号的办法

    set @strWhere=' AccountName like '+'''%'+@Condition+'%''' 先用'+''''+要在单引号里的内容+''''. 就这样就行了. 主要就是用三个单引 ...