uva748 - Exponentiation

  Exponentiation 

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 .

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 Rn. Leading zeros and insignificant trailing zeros should be suppressed in the output.

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

套用模版,注意小数的位数不足时要补0,后续0要清掉(其实对底数进行后续0清除就好了,因为出现后续0的唯一可能就是底数有后续0)

/*
高精度的幂。幂为低精度。
*/
#include <cstdio>
#include <iostream>
#include <cstring>
#include <climits>
using namespace std; #define maxn 30000 struct bign
{
int len, s[maxn]; bign()
{
memset(s, , sizeof(s));
len = ;
} bign(int num)
{
*this = num;
} bign(const char* num)
{
*this = num;
} bign operator = (int num)
{
char s[maxn];
sprintf(s, "%d", num);
*this = s;
return *this;
} bign operator = (const char* num)
{
len = strlen(num);
for (int i = ; i < len; i++) s[i] = num[len-i-] - '';
return *this;
} string str() const
{
string res = "";
for (int i = ; i < len; i++) res = (char)(s[i] + '') + res;
if (res == "") res = "";
return res;
} bign operator + (const bign& b) const
{
bign c;
c.len = ;
for (int i = , g = ; g || i < max(len, b.len); i++)
{
int x = g;
if (i < len) x += s[i];
if (i < b.len) x += b.s[i];
c.s[c.len++] = x % ;
g = x / ;
}
return c;
} void clean()
{
while(len > && !s[len-]) len--;
} bign operator * (const bign& b)
{
bign c; c.len = len + b.len;
for (int i = ; i < len; i++)
for (int j = ; j < b.len; j++)
c.s[i+j] += s[i] * b.s[j];
for (int i = ; i < c.len-; i++)
{
c.s[i+] += c.s[i] / ;
c.s[i] %= ;
}
c.clean();
return c;
} bign operator - (const bign& b)
{
bign c; c.len = ;
for (int i = , g = ; i < len; i++)
{
int x = s[i] - g;
if (i < b.len) x -= b.s[i];
if (x >= )
g = ;
else
{
g = ;
x += ;
}
c.s[c.len++] = x;
}
c.clean();
return c;
} bool operator < (const bign& b) const
{
if (len != b.len) return len < b.len;
for (int i = len-; i >= ; i--)
if (s[i] != b.s[i]) return s[i] < b.s[i];
return false;
} bool operator > (const bign& b) const
{
return b < *this;
} bool operator <= (const bign& b)
{
return !(b > *this);
} bool operator == (const bign& b)
{
return !(b < *this) && !(*this < b);
} bool operator != (const bign& b)
{
return (b < *this) || (*this < b);
} bign operator += (const bign& b)
{
*this = *this + b;
return *this;
}
}; istream& operator >> (istream &in, bign& x)
{
string s;
in >> s;
x = s.c_str();
return in;
} ostream& operator << (ostream &out, const bign& x)
{
out << x.str();
return out;
} int main()
{
bign a,ans;
int b;
string c; while (cin >> c >> b)
{
ans = ; int index = c.find('.'); if (index != -)
{
//后续0
for (int i = c.size()-; i > index; --i)
{
if (c[i] == '')
c.erase(i, );
else
break;
} c.erase(index, );
} index = c.size()-index; index *= b; a = c.c_str(); a.clean(); for (int i = ; i < b; ++i)
{
ans = ans*a;
} string s = ans.str(); //补0
int dif = s.size()-index;
if (dif >= )
{
s.insert(s.end()-index, '.');
}
else
{
for (int i = ; i < -dif; ++i)
{
s = '' + s;
}
s = '.' + s;
} cout << s << endl;
}
}

uva748 - Exponentiation 高精度小数的幂运算的更多相关文章

  1. 【POJ 1001】Exponentiation (高精度乘法+快速幂)

    BUPT2017 wintertraining(15) #6A 题意 求\(R^n\) ( 0.0 < R < 99.999 )(0 < n <= 25) 题解 将R用字符串读 ...

  2. hdu 1063 Exponentiation (高精度小数乘法)

    //大数继续,额,要吐了. Problem Description Problems involving the computation of exact values of very large m ...

  3. BigDecimal类(高精度小数)

    位置:java.math.BigDecimal 作用:提供高精度小数数据类型及相关操作 一.基本介绍 BigDecimal为不可变的.任意精度的有符号十进制数,其值为(unscaledValue * ...

  4. 算数运算符: + - * / //(地板除) %(取余) **(幂运算) / 比较运算符 > < >= <= == !=

    # ### python运算符 #(1) 算数运算符: + - * / //(地板除) %(取余) **(幂运算) var1 = 5 var2 = 8 # +res = var1 + var2 pri ...

  5. Modular_exponentiation模幂运算

    https://en.wikipedia.org/wiki/Modular_exponentiation 蒙哥马利(Montgomery)幂模运算是快速计算a^b%k的一种算法,是RSA加密算法的核心 ...

  6. POJ1026 Cipher(置换的幂运算)

    链接:http://poj.org/problem?id=1026 Cipher Time Limit: 1000MS   Memory Limit: 10000K Total Submissions ...

  7. 程序设计入门——C语言 第5周编程练习 1高精度小数(10分)

    1 高精度小数(10分) 题目内容: 由于计算机内部表达方式的限制,浮点运算都有精度问题,为了得到高精度的计算结果,就需要自己设计实现方法. (0,1)之间的任何浮点数都可以表达为两个正整数的商,为了 ...

  8. 组合数学 - 置换群的幂运算 --- poj CARDS (洗牌机)

    CARDS Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 1448   Accepted: 773 Description ...

  9. 迭代加深搜索 codevs 2541 幂运算

    codevs 2541 幂运算  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 钻石 Diamond 题目描述 Description 从m开始,我们只需要6次运算就可以计算出 ...

随机推荐

  1. AppIcon尺寸

  2. OOP Class具体解释

    对象[编辑] 对象(Object)是类的实例.比如."狗"这个类列举狗的特点,从而使这个类定义了世界上全部的狗. 而莱丝这个对象则是一条详细的狗,它的属性也是详细的.狗有皮毛颜色. ...

  3. java设计模式之模板方法

    转载请注明出处:http://blog.csdn.net/guolin_blog/article/details/8744002 今天你还是像往常一样来上班,一如既往地开始了你的编程工作. 项目经理告 ...

  4. vue 不能检测数组长度 值变化原因解析

    1.vue不能检测数组长度或者值的变化 (1)数组长度变化 未检测到 <!DOCTYPE html> <html lang="en"> <head&g ...

  5. 如何从官网下载Spring

    1.Spring下载地址http://repo.spring.io/release/org/springframework/spring/ 里面有各自版本下载: 方法二: 1.在百度中输入Spring ...

  6. CentOS下febootstrap自制Docker的CentOS6.6和7.1 Docker镜像

    docker image centos febootstrap CentOS 6.6和7.1 Docker自制CentOS镜像 安装: ? 1 yum -y install febootstrap 添 ...

  7. XML-RPC.NET

    XML-RPC.NET 是一个 .NET 的客户端服务器的基于 XML-RPC 远程过程调用的框架. 示例代码: [XmlRpcUrl("http://betty.userland.com/ ...

  8. Leetcode Find Minimum in Rotated Sorted Array 题解

    Leetcode Find Minimum in Rotated Sorted Array 题目大意: 对一个有序数组翻转, 就是随机取前K个数,移动到数组的后面,然后让你找出最小的那个数.注意,K有 ...

  9. js操作注意事项

    1.函数赋值给变量时,不能加括号 function fun() { ... } var str=fun; 2.js创建构造函数和调用对象,对象内不能用var 变量,只能用this function f ...

  10. 在Unity控制台下使用富文本

    之前都不知道,最近看了csdn一位开发者的博文突然发现 <b>asd</b> <color="red">asd</color> &l ...