分析:大实数乘方计算。

#include<iostream>
#include<string>
using namespace std; struct BigReal //高精度实数
{
int len; //长度
int num[10000];
int point; //小数点位置
BigReal()
{
len=1;
point=0;
memset(num,0,sizeof(num));
}
}; bool Read(BigReal& a) //读入一个大实数
{
string s;
int t,i; if(cin>>s)
{
a.len=s.size();
a.point=0;
t=0;
for(i=s.size()-1;i>=0;i--)
{
if(s[i]=='.')
{
a.len--;
a.point=t;
continue;
}
a.num[t++]=s[i]-'0';
}
return true;
}
else
return false;
} void Show(BigReal& a)
{
int i,pos; for(i=0;i<a.point && a.num[i]==0;i++) ;
pos=i;
if(a.point==a.len)
{
if(pos==a.point)
{
cout<<0<<endl; //0.0000000的情况
return ;
}
else
cout<<'.'; //0.121313114的情况
}
for(i=a.len-1;i>=0;i--)
{
cout<<a.num[i];
if(i==pos) break; //小数时后导零不输出
if(i==a.point) cout<<'.';
}
cout<<endl;
} BigReal Mul(const BigReal& a,const BigReal& b)
{
int i,j,len=0;
BigReal c; for(i=0;i<a.len;i++)
for(j=0;j<b.len;j++)
{
c.num[i+j]+=a.num[i]*b.num[j];
if(c.num[i+j]>=10)
{
c.num[i+j+1]+=c.num[i+j]/10;
c.num[i+j]%=10;
}
}
c.point=a.point+b.point;
len=a.len+b.len;
while(c.num[len-1]==0 && len>1&&len>c.point) len--; //处理长度,去掉前导零
if(c.num[len]) len++;
c.len=len;
return c;
} int main()
{
BigReal a;
int b; while(Read(a)&& scanf("%d",&b)==1)
{
BigReal ans;
ans.num[0]=1;
while(b--)
ans=Mul(ans,a);
Show(ans);
}
return 0;
}

HDU ACM 1063 Exponentiation 大实数乘方的更多相关文章

  1. Exponentiation(java 大实数)

    http://acm.hdu.edu.cn/showproblem.php?pid=1063 Exponentiation Time Limit: 2000/500 MS (Java/Others)  ...

  2. hdu acm 1028 数字拆分Ignatius and the Princess III

    Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K ...

  3. HDU 3533 Escape(大逃亡)

    HDU 3533 Escape(大逃亡) /K (Java/Others)   Problem Description - 题目描述 The students of the HEU are maneu ...

  4. hdu acm 2191 悼念512汶川大地震遇难同胞——珍惜现在,感恩生活

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2191 题目意思:有 资金 n 和 m 种类型的大米,对第 i 种类型的大米,价格.数量.袋数分别是: ...

  5. hdu 1063 Exponentiation

    求实数的幂,这个用C++写的话有点长,但是用Java写就非常方便了…… );            System.out.println(an);        }    }}

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

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

  7. hdu 1063 Exponentiation 大数

    Problem Description Problems involving the computation of exact values of very large magnitude and p ...

  8. hdu Exponentiation高精度实数乘幂(用了带小数的高精度模板)

    #include <cstdio> #include <cstring> #include <iostream> #include <cmath> #i ...

  9. HDU 1280 前m大的数

    http://acm.hdu.edu.cn/showproblem.php?pid=1280 前m大的数 Time Limit: 2000/1000 MS (Java/Others) Memory L ...

随机推荐

  1. 重写javascript浮点运算

    javascript中变量存储时不区分number和float类型,同一按照float存储; javascript使用IEEE 754-2008标准定义的64bit浮点格式存储number,decim ...

  2. Javascript 匀速运动停止条件——逐行分析代码,让你轻松了解运动的原理

    我们先来看下之前的匀速运动的代码,修改了速度speed后会出现怎么样的一个bug.这里加了两个标杆用于测试 <style type="text/css"> #div1 ...

  3. [MATLAB] 利用遗传算法函数求目标函数的最优解

    最近接触到了遗传算法以及利用遗传算法求最优解,所以就把这些相关的内容整理记录一下. 一.遗传算法简介(摘自维基百科) 遗传算法(英语:genetic algorithm (GA))是计算数学中用于解决 ...

  4. Oracle EBS-SQL (SYS-7):表单个性化查询.sql

    SELECT * FROM FND_FORM_CUSTOM_RULES; SELECT * FROM FND_FORM_CUSTOM_ACTIONS; SELECT * FROM FND_FORM_C ...

  5. USB OTG ID 检测原理

    OTG 检测的原理是: USB OTG标准在完全兼容USB2.0标准的基础上,增添了电源管理(节省功耗)功能,它允许设备既可作为主机,也可作为外设操作(两用OTG).USB OTG技术可实现没有主机时 ...

  6. delphi 编码速度提升技能

    效率,是一个永恒的主题. 本文重点强调 delphi ide 中的编码速度技能 一.TForm 窗口重用 当您在写一个管理类软件的时候,有大量的操作窗口,这些窗口会有大量共性.窗口重用就会发挥很大的作 ...

  7. c# webBrowser 获取Ajax信息 .

    c#中 webbrowser控件对Ajax的执行,没有任何的响应,难于判断Ajax是否已经执行完毕,我GG了一下午,找到一个方法,介绍一下: 假如在页面中有个<div id=result> ...

  8. InputStream、OutputStream、String的相互转换(转)

    //1.字符串转inputStream String string; //...... InputStream is = new ByteArrayInputStream(string.getByte ...

  9. Linux c 信号量

    信号量(通过进程通信实现进程间的同步) 信号量(semaphore)信号灯 信号量是共享内存整数数组.根据需要定义指定的数组长度 信号量就是根据数组中的值,决定阻塞还是解除阻塞 编程模型: 1.    ...

  10. storage theory

    preface/prehight:topic: Storage(share fileSystem(可共享文件系统,Access I/O existence bottleNeck,access read ...