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. react 设置代理(proxy) 实现跨域请求

    一,对于使用creat-react-app构建的项目,可以直接在package.json下配置,具体如下 "proxy": "http://api.xxxx.com&qu ...

  2. React.Fragment 包裹标签

    在 vue 里,我们会用 <template></template> 标签来包裹一些不能有父容器的复数同级标签. 例如在 <tbody></tbody> ...

  3. 两名技术人员,历经8小时Piranha Games成功集成Xsolla

    w=580&h=304" alt="" width="580" height="304" style="max- ...

  4. tomcat+nginx+redis集群试验

    Nginx负载平衡 + Tomcat + 会话存储Redis配置要点   使用Nginx作为Tomcat的负载平衡器,Tomcat的会话Session数据存储在Redis,能够实现0当机的7x24 运 ...

  5. 【ASP.NET MVC系列】详解View

    本篇文章内容属于ASP.NET MVC系列视图篇,主要讲解View,大致内容如下: 1.Views文件夹讲解 2.View种类 3.Razor语法 4.对视图的基本操作 一   Views文件夹 (一 ...

  6. convertView与ViewHolder有什么区别,好处在哪里

        convertView 在API中的解释是The old view to reuse, if possible, 第一次getView时还没有convertView,这时你便创建了一个新的vi ...

  7. spring-cloud-config笔记

    忽略元数据末尾 回到原数据开始处 spring-cloud-config 简单来讲就是spring-cloud实现的分布式配置中心.与之前介绍的开源配置服务方案 disconf是一样的,spring- ...

  8. unity, OnTriggerEnter2D不触发

    我两个物体A,B都添加了Circle Collider 2D,并且都勾选了is Trigger,我在A的脚本里用void OnTriggerEnter2D(Collider2D coll)检测碰撞,但 ...

  9. hdu4711Weather 概率dp

    //第i个城市到第j个城市的概率ma[i][j] //第i天的天气天气wet[i] //第i个城市天气为j的概率wet_m[i][j] //Hovey从0点開始,找出其概率最大的路线 //dp[i][ ...

  10. 生成ID模板:年月日时分秒+6位自增码

    因为生成订单ID.商品ID 或者什么什么ID的,不想用自增,又怕反复,于是就用  年与日时分秒 + 6位自增码 (共计20位长度)来当作ID 注意:假设你的ID是Long型.就要注意,Long的最大长 ...