分析:大实数乘方计算。

#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. Android API在不同版本系统上的兼容性

    随着安卓版本的不断更新,新的API不断涌出,有时候高版本的API会在低版本crash的. 如果minSdkVersion设置过低,在build的时候,就会报错(Call requires API le ...

  2. 退货行RMA编号改为必输选项

    应用 Oracle Inventory 层 Level Function 函数名 Funcgtion Name RCV_RCVTXERE 表单名 Form Name RCVTXERE 说明 Descr ...

  3. Tempo 2.0

    Tempo 2.0 Tempo is an easy, intuitive JavaScript rendering engine that enables you to craft data tem ...

  4. delphi 关于命名

    请告别 TMyXXX 的命名方法吧... 程序名: Demo.exe 窗体:TFrmDemo ,窗体文件 uFrmDemo.Pas DataModule: TDMDemo, 窗体文件 uDMDemo. ...

  5. Spring Boot的启动器Starter详解

    Spring Boot的启动器Starter详解 作者:chszs,未经博主允许不得转载.经许可的转载需注明作者和博客主页:http://blog.csdn.net/chszs Spring Boot ...

  6. 十度好友问题(DFS经典应用)

    问题: 在社交网络里(比如 LinkedIn),如果A和B是好友,B和C是好友,但是A和C不是好友,那么C是A的二度好友,给定一个社交网络的关系图,如何找到某一个人的所有十度好友.

  7. FineUI_动态绑定Grid

    private void InitGrid() { string _sql = GetSql().ToLower().Replace("select", "") ...

  8. CSV 客座文章系列: Pruffi 通过 Windows Azure 挖掘社交媒体的强大招聘潜能

    编辑人员注释:今天这篇文章由 Pruffi 创始人 Alena Vladimirskaya 和 Pruffi 的 CTO Alexander Ivanov 联合撰写,介绍了该公司如何使用 Window ...

  9. centos扩容(pv,vg,lv)

    preFace: (应用场景需求分析)

  10. MFC的命令行

    一个程序,我们通过输入不同的命令行参数,就可以实现一个可执行文件,多种功能,通过命令行来控制它的行为,例如,我们在控制台的时候,就是遇到最多的,如一个exe程序,加入为test..exe,我们可以设置 ...