求高精度幂(poj1001)
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
C++
while(cin>>s>>n)
{
…
}
c
while(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 /
{
…
}
#include <iostream>
#include <string.h>
using namespace std;
int a[200];
int main()
{
int n,i,j;
string s;
while(cin>>s>>n)
{
memset(a,0,sizeof(a));
if(n == 0)
{
cout<<1<<endl;
continue;
}
bool flag = 1;
int pos = 0,base = 0,count = 0,bit = 1;
for(i = s.length()-1,j = 0; i >= 0; i--)
{
if(s[i] == '0'&&flag) count++;
else
{
flag = 0;
if(s[i] == '.')
pos = s.length()-count-i-1;
else
{
a[j++] = s[i] - '0';
base += (s[i] - '0')*bit;
bit *= 10;
}
}
}
for(i = 0; i < n-1; i++)
{
int m = 0;
for(j = 0; j < 300; j++)
{
m += base * a[j];
a[j] = m % 10;
m /= 10;
}
}
for(i = 299; a[i] == 0&&i > pos*n-1; i--);
while(i >= 0)
{
if(i == pos*n-1)
cout<<".";
cout<<a[i];
i--;
}
cout<<endl;
}
return 0;
}
求高精度幂(poj1001)的更多相关文章
- Poj.Grids 2951 浮点数求高精度幂
2951:浮点数求高精度幂 总时间限制: 1000ms 内存限制: 65536kB 描述 有一个实数 R ( 0.0 < R < 99.999 ) ,要求写程序精确计算 R 的 n 次方. ...
- 求高精度幂(java)
求高精度幂 时间限制:3000 ms | 内存限制:65535 KB 难度:2 描述 对数值很大.精度很高的数进行高精度计算是一类十分常见的问题.比如,对国债进行计算就是属于这类问题. 现在要 ...
- 【ACM】求高精度幂
题目来源:http://poj.org/problem?id=1001&lang=zh-CN 求高精度幂 Time Limit: 500MS Memory Limit: 10000K To ...
- poj 1001 求高精度幂(Java, BigDecimal, pow, hasNext, stripTrailingZeros, toPlainString)
求高精度幂 Time Limit: 500MS Memory Limit: 10000K Total Submissions: 180325 Accepted: 43460 Descripti ...
- Exponentiation(求高精度幂)
Exponentiation Time Limit: 500MS Memory Limit: 10000K Total Submissions: 175340 Accepted: 42341 ...
- poj 1001 求高精度幂
本题的测试用例十分刁钻,必须要考虑到很多的细节问题,在这里给出一组测试用例及运行结果: 95.123 12 548815620517731830194541.899025343415715973535 ...
- C# 高精度求幂 poj1001
高精度求幂 public static char[] exponentiation(string a,int r) { ]; string b = ""; string c = a ...
- HDU 1402 A * B Problem Plus (FFT求高精度乘法)
A * B Problem Plus Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- 使用java求高精度除法,要求保留N位小数
题目要求是高精度除法,要求保留N位小数(四舍五入),并且当整数部分为0时去除0的显示 import java.math.BigDecimal; import java.util.Scanner; pu ...
随机推荐
- Git 常见工作流
多种多样的工作流使得在项目中实施Git时变得难以选择.这份教程提供了一个出发点,调查企业团队最常见的Git工作流. 阅读的时候,请记住工作流应该是一种规范而不是金科玉律.我们希望向你展示所有工作流,让 ...
- 「6月雅礼集训 2017 Day7」电报
[题目大意] 有n个岛屿,第i个岛屿有有向发射站到第$p_i$个岛屿,改变到任意其他岛屿需要花费$c_i$的代价,求使得所有岛屿直接或间接联通的最小代价. $1 \leq n \leq 10^5, 1 ...
- 虽然UIImageView是UIScollView的子视图,但UIImageView左上角是contentOfSet的原点
虽然UIImageView是UIScollView的子视图,但UIImageView左上角是contentOfSet的原点 https://www.evernote.com/shard/s22 ...
- POj 2104 K-th Number (分桶法+线段树)
题目链接 Description You are working for Macrohard company in data structures department. After failing ...
- 大聊Python----json与pickle数据序列化
用于序列化的两个模块 ☆json,用于字符串和python数据类型间进行转换 ☆pickle,用于python特有的类型和python的数据类型间进行转换 Json模块提供了四个功能:dumps.du ...
- java和C和C++关系
java和C以及C++ 直接关联,java继承了C的语法,java的对象模型是从C++改编而来的.java和C以及C++关系之所以重要,下面几个就是原因: ①如果一个程序员熟悉C以及C++语法,那么他 ...
- Linux二进制代码的阅读
大多数时候,我们研究的是如何阅读源代码.但在一些情况下,比如源代码不公开 或得到源代码的代价很高的情况下,我们又不得不需要了解程序的行为,这 时阅读二进制文件就非常重要.假设现在有一个二进制可执行文件 ...
- 利用最新Apache解析漏洞(CVE-2017-15715)绕过上传黑名单
转载自:https://www.leavesongs.com/PENETRATION/apache-cve-2017-15715-vulnerability.html 目标环境: 比如,目标存在一个上 ...
- Java中基于HotSpot虚拟机的垃圾收集器
名称 过程 优缺点 Serial 进行垃圾收集时,必须暂停其他所有的工作进程,直到它收集结束.是一个单线程收集器. Stop the world. 新生代收集器. 手工设置新生代的大小:-Xmn Ed ...
- java===java基础学习(1)---数据类型,运算,变量,常量
今天起开始了java的学习之路,主要学习了数据类型和运算,变量,常量.基本和python有很多相通的地方,所以看起来很容易上手.下面是学习笔记! package testbotoo; public c ...